Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Goods at a Specific Time

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

Your question is Goods at a Specific Time. 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

Flexport needs a point-in-time inventory view across its warehouse network. Given load and unload actions, write a PostgreSQL query that returns the amount of goods at every Flexport warehouse as of 2026-06-15 23:59:59+00.

Requirements

  1. Treat LOAD quantities as positive and UNLOAD quantities as negative.
  2. Include only actions that occurred at or before the specified timestamp.
  3. Include warehouses with no qualifying actions, returning 0 goods on hand.
  4. Return one row per warehouse, ordered by warehouse_id ascending.

Schema

warehouses
ColumnTypeDescription
warehouse_idPKINTEGERUnique warehouse identifier
facility_nameVARCHAR(100)Flexport warehouse name
cityVARCHAR(80)Warehouse city
inventory_actions
ColumnTypeDescription
action_idPKINTEGERUnique inventory action identifier
warehouse_idINTEGERWarehouse receiving the action
action_typeVARCHAR(20)Inventory action, such as LOAD or UNLOAD
quantityINTEGERNumber of goods affected by the action
occurred_atTIMESTAMPTZTimestamp when the action occurred
Tableswarehousesinventory_actions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results