Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Top Personal Shoppers by Performance
00:00
5 left

Top Personal Shoppers by Performance

MediumSQL · PostgreSQL

Problem

Given a transactional database table, write a query to identify top-performing personal shoppers based on delivery speed and customer ratings.

Use completed deliveries, require at least two completed deliveries and two non-null customer ratings per shopper, and return the top two shoppers. Delivery speed is measured in minutes from pickup to delivery.

Output

  1. One row per qualifying shopper with shopper_id, shopper_name, avg_delivery_minutes, avg_rating, completed_deliveries, and performance_rank.
  2. Sort by rank ascending, then shopper ID ascending. Faster average delivery ranks higher, followed by higher rating and more completed deliveries.

Schema

shoppers
ColumnTypeDescription
shopper_idPKINTUnique personal shopper identifier
shopper_nameVARCHAR(100)Personal shopper name
statusVARCHAR(20)Current shopper status
deliveries
ColumnTypeDescription
delivery_idPKINTUnique delivery identifier
shopper_idINTPersonal shopper assigned to the delivery
statusVARCHAR(20)Delivery lifecycle status
picked_up_atTIMESTAMPTimestamp when the order was picked up
delivered_atTIMESTAMPTimestamp when the order was delivered
customer_ratings
ColumnTypeDescription
rating_idPKINTUnique rating identifier
delivery_idINTDelivery being rated
rating_valueNUMERIC(2,1)Customer rating from 1.0 to 5.0
Tablesshoppersdeliveriescustomer_ratings
Interviewer

Your question is Top Personal Shoppers by Performance. Start with the requirements and the three tables in the Question tab.

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.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.