Top restaurant in each city

window functions

Top restaurant in each city

DoorDash SQL Interview Question

DoorDash's partnerships team wants to thank the best-selling restaurant in each city it serves.

For each city, find the restaurant_name with the highest total value of delivered orders, and that total as total_order_value. Each city has one clear top restaurant, so you do not need to handle ties.

Asked of

  • Data Analyst
  • Business Analyst
  • BI Analyst
  • Analytics Engineer
  • Data Engineer

deliveriesTable12 rows

Column NameType
delivery_idBIGINT
restaurant_idBIGINT
dasher_idBIGINT
ordered_atTIMESTAMP
delivered_atTIMESTAMP
order_valueDOUBLE
statusVARCHAR

restaurantsTable6 rows

Column NameType
restaurant_idBIGINT
restaurant_nameVARCHAR
cuisineVARCHAR
cityVARCHAR

deliveriesExample Input

delivery_idrestaurant_iddasher_idordered_atdelivered_atorder_valuestatus
70011512024-04-12 11:58:002024-04-12 12:26:0032.4delivered
70022522024-04-12 12:05:002024-04-12 12:41:0027.8delivered
70033532024-04-12 12:20:00NULL18.5canceled
70044542024-04-12 18:02:002024-04-12 18:48:0045.6delivered
70055552024-04-12 18:15:002024-04-12 18:37:0022.1delivered
70061522024-04-12 18:30:002024-04-12 19:04:0041.25delivered
70076562024-04-12 19:10:002024-04-12 19:52:0036.9delivered

restaurantsExample Input

restaurant_idrestaurant_namecuisinecity
1Taco LocoMexicanSan Francisco
2Pho RealVietnameseSan Francisco
3Burger BarnAmericanSan Francisco
4Curry HouseIndianDenver
5Nacho MamaMexicanDenver
6Big Bite BurgersAmericanDenver

Example Output

cityrestaurant_nametotal_order_value
DenverCurry House45.6
San FranciscoTaco Loco73.65

Explanation

Taco Loco delivered two orders in San Francisco worth 32.40 and 41.25, a total of 73.65, which beats Pho Real's 27.80. In Denver, Curry House leads with a single order worth 45.60. Burger Barn's canceled order does not count.

The example above is a small slice of the data. Your query runs against the full tables.