Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Window Functions for Throughput Trends

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

Your question is Window Functions for Throughput Trends. 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

MSD's research operations team needs a monthly view of completed experimental throughput for active programs. Write a PostgreSQL query that aggregates throughput by experiment date, then calculates cumulative and short-term throughput trends within each calendar month.

Requirements

  1. Join throughput_events to experiments and include only active experiments, completed runs, and nonnegative or NULL throughput values from January and February 2025.
  2. Aggregate throughput by event date and month, treating NULL throughput as zero.
  3. Use window functions partitioned by month to calculate a running total and a three-reported-day moving average, ordered chronologically.
  4. Return one row per reported date, ordered by month and event date.

Schema

experiments
ColumnTypeDescription
experiment_idPKINTUnique experiment identifier
experiment_nameVARCHAR(100)Name of the experiment
therapeutic_areaVARCHAR(80)Therapeutic research area
statusVARCHAR(20)Current experiment program status
throughput_events
ColumnTypeDescription
event_idPKINTUnique throughput event identifier
experiment_idINTExperiment associated with the event
event_dateDATEDate throughput was recorded
throughput_samplesINTNumber of processed samples
run_statusVARCHAR(20)Execution status of the run
Tablesexperimentsthroughput_events
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results