← Back to problems Next: LEFT JOIN anti →

JOIN + GROUP BY + SUM

Relational aggregation — half of the common GM SQL bar

SQL drill • Aggregations

Tables: customers(id, name) and orders(id, customer_id, amount).
Return each customer name with their total spend (sum of amount), only for customers who have orders. Order by total descending.
SQL is rarely the whole interview, but it appears enough that you should be prepared. Many GM-style questions boil down to: can you JOIN facts to dimensions and GROUP BY the right grain? If yes, you are in good shape on that axis.

Mental model
Filter rows → bucket → fold
Step 0/7 Focus line
Join alignment Group bucket Aggregate result
Conceptual evaluation
Press Step or Play.
Ready
Walk through how SQL evaluates JOIN, then GROUP BY, then SUM — in that mental order.