Complete the code to start a Common Table Expression (CTE) in Snowflake.
WITH [1] AS (SELECT * FROM employees)The name of the CTE comes right after the WITH keyword. Here, cte is a placeholder for the CTE name.
Complete the code to select all columns from the CTE named 'sales_data'.
SELECT * FROM [1];To use the CTE, you select from its name. Here, the CTE is named sales_data.
Fix the error in the CTE syntax by completing the missing keyword.
WITH sales_summary [1] (SELECT region, SUM(amount) FROM sales GROUP BY region) SELECT * FROM sales_summary;The keyword AS is required after the CTE name to define its query.
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 orders GROUP BY customer_id) SELECT * FROM top_customers;
The CTE name is top_customers and the keyword AS defines the CTE query.
Fill all three blanks to create two CTEs named 'recent_orders' and 'high_value' and select from 'high_value'.
WITH [1] [2] (SELECT * FROM orders WHERE order_date > CURRENT_DATE - INTERVAL '30' DAY), [3] AS (SELECT * FROM [1] WHERE amount > 1000) SELECT * FROM high_value;
The first CTE is named recent_orders, followed by the keyword AS. The second CTE is named high_value.