Skip to main content
SQL-FUNDAMENTALS5 MIN READ

Build a clean monthly revenue query

Write a grouped monthly revenue query with row filters before aggregation.

Create one row per month per region for paid non-test revenue. Filter rows first; group by the dimensions in the output grain; aggregate only the measure. Grouping before eligibility is clear causes cancelled and test rows to enter the metric. 1 WHERE status = 'paid' AND is_test = false Only eligible raw rows enter the aggregate. 2 GROUP BY month_start, region This declares one output row per month per region. 3 SELECT month_start, region, SUM(line_revenue) AS revenue The aggregate now summarizes the intended group. The query returns 36 rows for 12 months times 3 regions, and totals match the finance…

Read the full lesson

Sign up free — one personalized lesson every day, matched to your role and goals.

Already have an account? Sign in

← Back to library
Contact us