Exam 6: Aggregating Data
Difficulty: Intermediate
Topics covered: COUNT, SUM, AVG, GROUP BY, HAVING
Each question shows the target output. Write a SQL query that produces exactly those columns and rows.
Question 1
Count the total number of orders. Return a single column named total_orders.
Question 2
Find the total revenue from all completed orders. Return a single column named total_revenue.
Question 3
For each product category, calculate the average price. Return category and avg_price.
Question 4
For each customer, count how many orders they have placed. Return customer_id and order_count. Only include customers with more than 1 order.
Question 5
For each product, calculate the total quantity ordered and the total revenue. Join with products to include the product name aliased as product_name. Only include products where the total quantity is 5 or more. Return product_name, total_qty, and total_revenue.