▸_sqlgym

44. Big Spenders (HAVING Threshold)

MediumAggregationGROUP BYHAVINGSUM

WHERE filters individual rows before grouping; HAVING filters whole groups after aggregation, so it can reference aggregate values like SUM(...).

Task: return each customer whose total spend is at least 100, along with that total.

Return columns customer, total_spent where total_spent = SUM(amount). Keep only groups with total_spent >= 100. Order by total_spent descending, then 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.