43. Revenue By Category
EasyAggregationGROUP BYSUMAVGROUND
Several aggregates can be computed in a single GROUP BY pass.
Task: for each product category, return the total and average sale amount.
Return columns category, total, avg_amount, where total = SUM(amount) and avg_amount = ROUND(AVG(amount), 2) (round to 2 decimals). Order by total descending, then category 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· SQLite · runs in your browser
⌘/Ctrl+↵ run · ⇧⌘/Ctrl+↵ submit
Run a query to see its output here.