All topics / Build an Expense Analytics Report (SQL)

Build an Expense Analytics Report (SQL)

Go from a raw expenses table to a real monthly report in SQL - grouping, aggregates, and window functions - all runnable in your browser.

  1. The Schema and Seed Data Create the expenses table and fill it with a few dozen realistic rows you can query for the rest of the project.
  2. Totals and Groups Collapse the raw rows into spend per category and spend per month using GROUP BY and SUM.
  3. Running Totals with Window Functions Compute a running total and a month-over-month change with SUM() OVER and LAG, keeping every row instead of collapsing it.
  4. The Final Report Fold category share-of-total and the month-over-month trend into one report query you could drop into a dashboard.