Skip to main content

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.

⌘ / Ctrl + Enter to run

Question 2

Find the total revenue from all completed orders. Return a single column named total_revenue.

⌘ / Ctrl + Enter to run

Question 3

For each product category, calculate the average price. Return category and avg_price.

⌘ / Ctrl + Enter to run

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.

⌘ / Ctrl + Enter to run

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.

⌘ / Ctrl + Enter to run
Donate to this project