Complete the code to start a WITH clause in PostgreSQL.
WITH [1] AS (SELECT * FROM employees) SELECT * FROM [1];
The WITH clause defines a temporary named result set. You name it first, like temp_table.
Complete the code to define a WITH clause that selects all from the sales table.
WITH sales_data AS ([1] * FROM sales) SELECT * FROM sales_data;The WITH clause contains a subquery, so it must start with SELECT to retrieve data.
Fix the error in the WITH clause by choosing the correct keyword.
WITH recent_orders AS (SELECT * [1] orders WHERE order_date > '2024-01-01') SELECT * FROM recent_orders;
In a SELECT statement, you specify the table with the FROM keyword.
Fill both blanks to create a WITH clause that calculates total sales per customer.
WITH total_sales AS (SELECT customer_id, SUM(amount) [1] sales [2] customer_id) SELECT * FROM total_sales;
The SUM aggregation requires a FROM clause to specify the table, and a GROUP BY clause to group results by customer.
Fill all three blanks to write a WITH clause that finds customers with orders over 100, then selects their names.
WITH high_value_customers AS (SELECT customer_id [1] orders [2] amount > 100 GROUP BY customer_id [3] SUM(amount) > 100) SELECT name FROM customers WHERE id IN (SELECT customer_id FROM high_value_customers);
The subquery selects customer_id from orders (FROM), filters rows with WHERE, and uses HAVING to filter groups after aggregation.