Each Country Against the Average

easy
Unit 6 · Window Functions I0/3 to milestone

Return each country's total revenue and pct_vs_avg: how far it is above or below the average country revenue, as a percentage rounded to 1 decimal place. Only countries with orders count. Sort by revenue descending, then country.

A window function over an aggregated CTE avoids a second query.

Schema

customers(id, name, country, signup_date)
orders(id, customer_id, order_date, total)
#window-functions#aggregation1 visible + 1 hidden tests
query.sql · SQLite
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Each Country Against the Average · TechGradify