Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Compute Delta Between Events

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

Your question is Compute Delta Between Events. 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

The monday Work Management team wants to monitor how long items remain open on a board. Given separate creation and completion event tables, write a PostgreSQL query that calculates the elapsed time between the two timestamped events for every created item.

Requirements

  1. Start with every item in item_created_events, including items without a completion event.
  2. Join a matching completion event from item_completed_events using item_id.
  3. Return the elapsed time in hours as delta_hours, rounded to two decimal places. Return NULL when the completion timestamp is unavailable.
  4. Order the results chronologically by the creation timestamp.

Schema

item_created_events
ColumnTypeDescription
item_idPKBIGINTUnique monday item identifier
created_atTIMESTAMPTZTimestamp when the item was created
item_completed_events
ColumnTypeDescription
item_idPKBIGINTmonday item identifier associated with the completion event
completed_atTIMESTAMPTZTimestamp when the item was completed
Tablesitem_created_eventsitem_completed_events
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results