SQL
All Top 50 SQL Interview Questions#19
Multi-Table 3-Way Joins for Business Analytics in SQL
MediumInterview Question #19
Given `users`, `orders`, and `order_items`, write a SQL query to return `user_name`, `product_category`, and total spend for that category. Only include completed orders.
Input Table: users, orders, order_items
2 rows preview| user_id | order_id | item_id | category | price |
|---|---|---|---|---|
| 1 | 101 | 501 | Electronics | 12000 |
| 1 | 102 | 502 | Books | 800 |
Expected Output Structure2 rows
| user_name | product_category | category_spend |
|---|---|---|
| Aarav | Electronics | 12000 |
| Aarav | Books | 800 |
Interview Context
Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.
PostgreSQL 15
Ready to execute
Click "Run Query" or press Ctrl + Enter to test your query.
Output will be verified against the test dataset.