Practice SQL questions.
Prepare for interviews with ecommerce and finance SQL questions. Write and run queries on Northstar’s orders, payments, and refunds—from basic aggregations to window functions and first-order cohorts.
Read the business definition and explore the table schema and sample rows.
Write your SQL from scratch and run it locally against the practice data.
Compare results against a reference on the visible data and an amount variation—not against query text.
Build the foundations.
Filters, dates, joins, aggregation, and financial grain.
Completed orders over $100
SELECT · WHERE · ORDER BY
Missing customer emails
NULL · Filtering
Count orders by status
COUNT · GROUP BY
Monthly completed revenue
SUM · Dates · GROUP BY
Average order value
AVG · ROUND
Buyers with more than three orders
HAVING · Aggregation
Customers who never ordered
LEFT JOIN · Anti join
Revenue by buyer country
JOIN · SUM
One row per customer, all statuses
CASE · Conditional aggregation
Revenue from order lines
Multiple joins · SUM
Captured cash minus successful refunds
Subqueries · COALESCE · Finance
March customers above $200
Dates · HAVING · SUM
Go beyond GROUP BY.
ROW_NUMBER, RANK, DENSE_RANK, LEAD, LAG, running totals, and cohorts.
Each buyer’s first completed order
ROW_NUMBER · First order
First-ever order in March, over $100
ROW_NUMBER · Cohorts · Filtering
March spending ranks with gaps
RANK · Ties
Top three spending tiers
DENSE_RANK · Ties
Days since the previous order
LAG · Dates
Days until the next purchase
LEAD · Dates
Running customer spending
SUM OVER · Window frames
Month-over-month revenue change
LAG · CTE · Finance
A second purchase within seven days
ROW_NUMBER · Retention
Largest order in each country
RANK · PARTITION BY
Customer net collections without fan-out
CTE · Preaggregation · Finance
Fill missing months before accumulating
Calendar · LEFT JOIN · SUM OVER
Explore the Northstar dataset before starting
Data & schema
- customer_id
- INTEGER · PK
- customer_name
- VARCHAR
- country
- VARCHAR
- VARCHAR
- signup_date
- DATE
Table notes & relationships
Buyer accounts. Some buyers have no orders, and some email addresses are NULL.
Fictional teaching data. Money is USD cents; timestamps are UTC.