▸_sqlgym

40. Spend per Customer Across Three Tables

HardJoinsthree-table joinGROUP BYSUM

Real schemas spread data across several tables. Here a customer has many orders, and each order has many line items. To total what each customer spent you must chain three joins, then aggregate.

Task: for each customer return their name and total_spent, the sum of qty * price over all line items across all their orders.

Output columns, in this exact order: customer, total_spent. Order by total_spent descending, breaking ties by customer ascending.

Tables
Loading schema…
Expected outputrows must come back in this order
Computing expected output…

This is the result for the example data above. On Submit your query is graded against this example plus 4 hidden edge cases 5test cases in all. A sloppy query that only fits the example won't pass.

SQL
⌘/Ctrl+↵ run · ⇧⌘/Ctrl+↵ submit
Run a query to see its output here.