Complete the code to create a CTE named 'recent_orders' that selects orders from 2023.
WITH [1] AS (SELECT * FROM orders WHERE order_date >= '2023-01-01') SELECT * FROM recent_orders;
The CTE name must match the name used later in the query. Here, 'recent_orders' is the correct name.
Complete the code to select customer_id and total from the CTE named 'customer_totals'.
WITH customer_totals AS (SELECT customer_id, SUM(amount) AS total FROM sales GROUP BY customer_id) SELECT [1] FROM customer_totals;You need to select the columns defined in the CTE: customer_id and total.
Fix the error in the CTE query by completing the missing keyword.
WITH recent_orders [1] (SELECT * FROM orders WHERE order_date >= '2023-01-01') SELECT * FROM recent_orders;
The keyword 'AS' is required after the CTE name to define the CTE query.
Fill both blanks to create a CTE that calculates average sales and then selects customers with sales above 1000.
WITH avg_sales AS (SELECT customer_id, AVG(amount) [1] sales_avg FROM sales GROUP BY customer_id) SELECT customer_id, sales_avg FROM avg_sales WHERE sales_avg [2] 1000;
The alias keyword 'AS' names the average column, and '>' filters customers with sales above 1000.
Fill all three blanks to create a CTE that finds top products by total sales and selects those with sales over 5000.
WITH top_products AS (SELECT product_id, [1](quantity * price) [2] total_sales FROM sales GROUP BY product_id) SELECT product_id, total_sales FROM top_products WHERE total_sales [3] 5000;
SUM calculates total sales, AS names the column, and > filters products with sales over 5000.