▸_sqlgym

20. Percent of Category Total

MediumWindow FunctionsSUM() OVER PARTITION BYratio to group total

A PARTITION BY window aggregate gives each row a group total without a GROUP BY — perfect for "share of total" calculations.

Task: for each product return product, category, and pct — its revenue as a percentage of its category's total revenue. Round to 1 decimal. Order by category, then product.

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.