Sales analysis with SQL
Load a real retail dataset and answer the questions a business analyst gets asked every week.
What you'll learn
- โImporting CSV data
- โCTEs and window functions
- โTurning questions into queries
What you'll build
- โMonthly revenue and growth %
- โTop products and customers
- โRepeat-customer rate
- โCohort retention table
Step-by-step guide
- 1
Get data
Use a public dataset such as the "Superstore" sales CSV or the UCI Online Retail dataset.
- 2
Load it
CREATE TABLE matching the columns, then COPY (PostgreSQL) or .import (SQLite). Fix dates and nulls.
- 3
Monthly revenue
SELECT DATE_TRUNC('month', order_date), SUM(sales) ... GROUP BY 1; growth with LAG() OVER (ORDER BY month).
- 4
Top N per group
Top 3 products in each category with ROW_NUMBER() OVER (PARTITION BY category ORDER BY revenue DESC).
- 5
Customers
Repeat-customer rate = customers with 2+ orders / all customers, using a CTE.
- 6
Cohorts
First-purchase month per customer, then the share still buying 1, 2, 3 months later.
- 7
Write it up
A short report: 5 findings with the query and a chart for each (export results to Excel or use Python).
๐ Make it stand out
- +Build a dashboard on top (Power BI or Metabase)
- +RFM customer segments
- +Discount impact analysis