Complete the code to start a Common Table Expression (CTE) named 'recent_orders'.
WITH [1] AS (SELECT * FROM orders WHERE order_date > '2024-01-01') SELECT * FROM recent_orders;
The CTE name must match the name used after WITH and in the main query. Here, 'recent_orders' is the correct CTE name.
Complete the code to select customer_id and total_orders from the CTE named 'order_counts'.
WITH order_counts AS (SELECT customer_id, COUNT(*) AS total_orders FROM orders GROUP BY customer_id) SELECT [1] FROM order_counts;To get both customer_id and total_orders columns, list them separated by a comma in the SELECT statement.
Fix the error in the CTE by completing the missing keyword.
WITH recent_orders [1] (SELECT * FROM orders WHERE order_date > '2024-01-01') SELECT * FROM recent_orders;
The keyword 'AS' is required after the CTE name to define the query that forms the CTE.
Fill both blanks to create a CTE named 'top_customers' that selects customer_id and total_spent.
WITH [1] [2] (SELECT customer_id, SUM(amount) AS total_spent FROM sales GROUP BY customer_id) SELECT * FROM top_customers;
The CTE name is 'top_customers' and the keyword 'AS' is needed after the name to define the CTE query.
Fill all three blanks to create a CTE named 'high_value_orders' that selects order_id and total from orders where total > 1000.
WITH [1] [2] (SELECT order_id, total FROM orders WHERE total [3] 1000) SELECT * FROM high_value_orders;
The CTE name is 'high_value_orders', the keyword 'AS' is required, and the condition uses '>' to select totals greater than 1000.