DataLane

13. Revenue share by country

mediumProNot started~12 minWindow functionsAggregation

Asked in screens shaped like: Amazon, Shopify, Meta

Each country needs its percentage of total completed revenue on the same row as its own revenue. A second query for the grand total works but scans the table twice — do it with one window instead.

Requirements

  • Columns: country, revenue, pct_of_total
  • Only status = 'completed'
  • pct_of_total is revenue / total revenue as a percentage, rounded to 2 decimals
  • revenue rounded to 2 decimals, ordered by revenue descending

Expected output

country, revenue, pct_of_total

Row order is graded, so ORDER BY matters here.

SQL editor

Loading SQL engine…

Ctrl/Cmd + Enter submits

Run your query to see the result set.

Pro problem

Medium problems unlock with Pro

Easy pads stay free. Medium and hard SQL and Python problems — editor, tests, hints, and solutions — open after you upgrade to Pro or coaching.

See plansPractice free easy problems
↑↓ navigate openesc close