Complete the code to select only distinct customer IDs from the orders table.
SELECT [1] customer_id FROM orders;The DISTINCT keyword removes duplicate rows, returning unique customer IDs.
Complete the code to create an index on the email column of the users table to speed up searches.
CREATE INDEX [1] ON users(email);Index names often start with idx_ to indicate an index. idx_email is a clear, valid name.
Fix the error in the query that tries to filter orders with total greater than 100 but uses the wrong clause.
SELECT * FROM orders [1] total > 100;
The WHERE clause filters rows before grouping or aggregation. Use it to filter orders with total > 100.
Fill both blanks to write a query that uses a CTE to get top 5 products by sales and then selects their names.
WITH top_products AS (SELECT product_id, SUM(sales) [1] sales_total FROM sales_data GROUP BY product_id ORDER BY sales_total DESC [2] 5) SELECT product_name FROM products WHERE product_id IN (SELECT product_id FROM top_products);
Use AS to alias the sum as sales_total. Use LIMIT to restrict to top 5 rows.
Fill all three blanks to write a query that aggregates total sales per region, filters regions with sales over 10000, and orders results descending.
SELECT region, SUM(sales) [1] total_sales FROM sales GROUP BY [2] HAVING total_sales [3] 10000 ORDER BY total_sales DESC;
Alias the sum as total_sales using AS. Group by region. Filter with > to get regions with sales over 10000.