For data analyst & data scientist interviews
Practise SQL interview questions on realistic data
Try one now: edit the query and press Run & check. It runs in your browser, no signup.
Revenue by Product Category
Finance wants a quick view of which product categories bring in the most money. Calculate total revenue per category, counting only completed orders. Line revenue is quantity times unit_price.
Expected output: category, revenue (rounded to 2 decimals). Highest revenue first.
customers(customer_id, name, country, signup_date, referred_by)
products(product_id, name, category, price)
orders(order_id, customer_id, order_date, status)
order_items(order_id, product_id, quantity, unit_price)
Expected output preview (5 rows, order matters)
| category | revenue |
|---|---|
| Electronics | 8311.74 |
| Home | 6169.04 |
| Apparel | 4783.72 |
Showing 3 of 5 rows.
Hints
Worked solution
Run at least one query to unlock it.70 original problems on window functions, retention cohorts, funnels, self-joins and attribution. 24 easy · 30 medium · 16 hard · 12 free without an account
Runs in your browser
A real SQLite engine runs on your device. No setup and no waiting for a server.
Instant answer checks
Your result is compared with the expected output. Row order is ignored unless the question asks for it.
Explanations that teach
Every problem has progressive hints and a worked solution explaining the pattern and the common traps.
Four realistic datasets
E-commerce store
An online store selling electronics, home goods, books, apparel and beauty products to customers in six countries (Jan 2025 to Mar 2026).
customers · products · orders · order_items
Ride-share marketplace
Trip requests in four US cities from January to March 2026, with drivers, riders, fares and ratings.
drivers · riders · trips
B2B SaaS product events
A project-management SaaS: company accounts, their users, product event logs (Jan to Apr 2026) and subscription history.
accounts · users · events · subscriptions
Digital ads performance
A retailer's paid campaigns across search, social, display and video in February 2026: daily delivery, individual ad clicks and purchases.
campaigns · ad_daily · ad_clicks · conversions
Practise by topic
Start with the free problems
No account needed. Sign up free to unlock the rest and save your progress.
- Revenue by Product CategoryfreeAggregation & GROUP BY · Joinseasy
- Customers Who Never OrderedfreeJoinseasy
- Monthly Revenue TrendfreeDates & Time · Aggregation & GROUP BYeasy
- Average Order Value by CountryfreeAggregation & GROUP BY · Subqueries & CTEseasy
- Top 2 Products in Each CategoryfreeWindow Functions · Ranking & Top-N per Groupmedium
- Completed Trips and Gross Fares by CityfreeAggregation & GROUP BYeasy
- Cancellation Rate by CityfreeConditional Aggregationeasy
- Drivers with No Completed Trips in MarchfreeJoins · Subqueries & CTEseasy
- Signups by Acquisition ChannelfreeAggregation & GROUP BYeasy
- Ordered Activation FunnelfreeFunnels & Activation · Subqueries & CTEshard
- Click-Through Rate by ChannelfreeAggregation & GROUP BY · Joinseasy
- Last-Touch Attribution by ChannelfreeMarketing Attribution · Window Functionshard