▸_sqlgym

3. Above-Average Spenders

MediumCTEsmultiple CTEsaggregate then compare

Common Table Expressions let you name intermediate results and chain them. Here you need two: one for the global picture, one per customer.

Task: find customers whose average order amount is greater than the global average order amount across all orders. Return customer and their rounded average cust_avg (2 decimals), ordered by cust_avg descending.

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.