▸_sqlgym

57. Top Spenders via a Derived Table

MediumSubqueriesderived tablesubquery in FROMGROUP BYHAVING

A derived table is a subquery in the FROM clause that you treat like a temporary table. It is handy when you must aggregate first and then filter or join on the aggregate.

Task: using a derived table that totals each customer's spend, return the customers whose total spend is at least 100.

Return columns name, total_spent. Order by total_spent descending, then name 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.