Complete the code to define a 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. 'recent_orders' is the correct name here.
Complete the code to write a subquery that selects customers with orders over 100.
SELECT customer_id FROM customers WHERE customer_id IN (SELECT [1] FROM orders WHERE amount > 100);
The subquery must select customer_id to match the outer query's WHERE condition.
Fix the error in the view creation statement by filling the blank.
CREATE VIEW [1] AS SELECT product_id, SUM(quantity) AS total_qty FROM sales GROUP BY product_id;The view name should be descriptive and consistent. 'sales_summary' clearly describes the content.
Fill both blanks to write a query using a CTE and filter results.
WITH high_sales AS (SELECT customer_id, SUM(amount) AS total FROM orders GROUP BY customer_id) SELECT * FROM high_sales WHERE total [1] [2];
The query filters customers with total sales greater than 1000.
Fill all three blanks to create a view that shows average order amount per customer with a filter.
CREATE VIEW [1] AS SELECT customer_id, AVG(amount) AS avg_amount FROM orders GROUP BY [2] HAVING AVG(amount) [3] 50;
The view name is 'customer_avg_order', grouping is by 'customer_id', and the HAVING clause filters averages greater than 50.