All courses
Beginner

Totals, averages and groups

Turn raw rows into the numbers a manager asks for: counts, revenue, average order value, monthly trends and rates per group.

8 exercises · 31 minutes · Data: Online shop
Start course
SQL
01
→ 02
→ 03

Your exercises

01
How big is our customer base?Free

For the investor update, the founder wants two numbers in one row: how many customers we have, and in how many different countries they live. Return the customer count first, then the number of distinct countries.

2 min
02
Total paid revenue

What did we actually earn in 2026? Revenue of an order line is quantity × unit_price, and only orders with status 'paid' count. Return a single value: total paid revenue rounded to 2 decimals. The starter already connects each order line to its order.

3 min
03
Catalogue overview by category

The buyer wants a quick overview of the catalogue. For each product category return: category, number of products, and average list price rounded to 2 decimals. Sort by category A to Z.

3 min
04
Average order value

Average order value (AOV) is a key e-commerce KPI: total revenue divided by the number of orders. Using paid orders only, return two values: the number of paid orders, then the AOV rounded to 2 decimals (revenue = quantity × unit_price).

4 min
05
Top 3 best sellers

Which products move the most units? Using paid orders only, return product name and total units sold (sum of quantity) for the 3 products with the most units, sorted by units sold from high to low, then by product name A to Z.

4 min
06
Customers with 3+ paid orders

The loyalty team wants to reward repeat buyers. Return customer_id and number of paid orders for every customer with at least 3 paid orders. Sort by number of paid orders from high to low, then by customer_id ascending.

4 min
07
Monthly revenue trend

Finance wants the 2026 revenue trend. Using paid orders only, return month (text in 'YYYY-MM' format, e.g. '2026-01') and revenue (quantity × unit_price) rounded to 2 decimals, one row per month, sorted from the earliest month to the latest.

5 min
08
Refund rate per sales channel

Customer service suspects one sales channel has more refunds. For each channel return: channel, total number of orders (any status), number of refunded orders, and refund rate as a percentage of all orders rounded to 2 decimals (e.g. 12.5 for 12.5%). Sort by refund rate from high to low.

6 min
Queries run on sample company data in SQLite. Core SELECT, JOIN and GROUP BY patterns transfer to other SQL engines; functions, dates and types can differ.