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.
Start course→ 02
→ 03
Your exercises
01For 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.
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.
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.
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).
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.
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.
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.
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.