Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top 10% Underperforming Zones

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

Your question is Top 10% Underperforming Zones. 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 Operations wants to identify active delivery zones with the longest completed-order delivery times. Write a PostgreSQL query that returns the top 10% of qualifying zones by average delivery duration.

Requirements

  1. Join swiggy_zones with swiggy_deliveries using zone_id.
  2. Consider only active zones and deliveries with status = 'DELIVERED' and non-null timestamps.
  3. Calculate average delivery time in minutes and the number of completed deliveries per zone.
  4. Rank zones from slowest to fastest and return CEIL(10% of qualifying zones), with ties resolved by zone_id.

Schema

swiggy_zones
ColumnTypeDescription
zone_idPKINTEGERUnique Swiggy delivery zone identifier
zone_nameVARCHAR(80)Name of the delivery zone
cityVARCHAR(60)City containing the zone
is_activeBOOLEANWhether the zone is currently active
swiggy_deliveries
ColumnTypeDescription
delivery_idPKINTEGERUnique delivery identifier
zone_idINTEGERDelivery zone associated with the order
statusVARCHAR(20)Delivery lifecycle status
accepted_atTIMESTAMPTimestamp when the delivery was accepted
delivered_atTIMESTAMPTimestamp when the order was delivered
Tablesswiggy_zonesswiggy_deliveries
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results