← All SQL interview questions

City share of total revenue with running share

MediumWindow FunctionsZomatoOla

A regional head wants to know how concentrated revenue is across cities.

From city_sales, return city, city_revenue, share_pct (the city's percentage of total revenue, 1 decimal) and cumulative_share_pct (running total of the share when cities are sorted from highest to lowest revenue, 1 decimal). Order by city_revenue descending.

Sample data

Table: city_sales

16 row(s) · showing first 8

txn_idINTcityTEXTrevenueNUMERIC(10,2)
1Bengaluru52000.00
2Bengaluru38000.00
3Bengaluru41000.00
4Mumbai47000.00
5Mumbai36000.00
6Mumbai29000.00
7Delhi44000.00
8Delhi31000.00