Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Restaurants by Order Volume

EasySQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Top Restaurants by Order Volume. Start with the requirements and the two tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Swiggy's Business Analytics team wants to identify the restaurants with the highest completed order volume. Assume the report date is 2025-02-15, so the previous calendar month is January 2025.

Write a PostgreSQL query to return the top three restaurants by completed order volume during that month.

Requirements

  1. Join restaurants to orders using restaurant_id.
  2. Include only orders with status COMPLETED placed from 2025-01-01 through, but not including, 2025-02-01.
  3. Return each restaurant's name and completed order count, ordered from highest to lowest. Break ties using ascending restaurant_id and return only three rows.

Schema

restaurants
ColumnTypeDescription
restaurant_idPKINTEGERUnique restaurant identifier
restaurant_nameVARCHAR(120)Restaurant display name
cityVARCHAR(80)Swiggy service city
is_activeBOOLEANWhether the restaurant is currently active
orders
ColumnTypeDescription
order_idPKBIGINTUnique order identifier
restaurant_idINTEGERRestaurant associated with the order
order_placed_atTIMESTAMPTimestamp when the order was placed
order_statusVARCHAR(20)Order lifecycle status
order_valueNUMERIC(10,2)Gross order value in INR
Tablesrestaurantsorders
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results