Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Dasher Waiting Time Query

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

Your question is Dasher Waiting Time Query. Start with the requirements and the one table 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

DoorDash operations wants to measure how long each Dasher spent in the waiting_for_order status during a reporting period. Status logs represent status changes, so each row remains active until the next status event for that Dasher.

Write a PostgreSQL query for the period from 2025-02-01 00:00:00 through 2025-02-02 12:00:00.

Requirements

  1. Use a window function to determine when each status interval ends.
  2. Count only time during waiting_for_order, clipping intervals to the reporting boundaries.
  3. Include every Dasher represented in the logs, including those with zero waiting time.
  4. Return total waiting time in seconds, ordered by dasher_id.
  5. Treat an open-ended final status as continuing through the report end, and ignore logs that do not overlap the reporting period.

Schema

dasher_status_logs
ColumnTypeDescription
log_idPKINTUnique status log identifier
dasher_idINTDoorDash Dasher identifier
statusVARCHAR(40)Dasher status beginning at status_at
status_atTIMESTAMPTimestamp when the status began
notesTEXTOptional operational note
Tablesdasher_status_logs
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results