Back to Practice
#0333
Percent of Total Revenue
MediumSQL24 min20 XP
Problem
Return category, revenue, and pct_total as revenue divided by total revenue.
Why This Matters
SQL interviews usually test whether you can turn a business question into the right rows, grouping level, join type, and edge-case behavior.
Schema
sales(category TEXT, amount REAL)
Examples
Example 1
InputA and B each have 100 revenue
Outputeach category has 0.5
SUM(revenue) OVER () gives the grand total alongside each row.
Constraints
- Return only the requested columns.
- Use deterministic ORDER BY when multiple rows are returned.
- Assume SQLite-compatible SQL unless the prompt states otherwise.
CodeSQL
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core SQL case
InputA and B each have 100 revenue
Expected[["A",100,0.5],["B",100,0.5]]
SUM(revenue) OVER () gives the grand total alongside each row.
Hidden Test Categories
Empty or missing matchesDuplicate rows or tiesNULL values where the pattern commonly breaks