Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rolling Window Genomic Orders

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

Your question is Rolling Window Genomic Orders. 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

Tempus AI uses genomic test order data to monitor patient testing activity over time. Write a PostgreSQL query that calculates the rolling three-month average of completed genomic test orders for every patient.

Requirements

  1. Aggregate completed genomic test orders by patient and calendar month.
  2. Include months with zero completed orders, including patients with no orders.
  3. Use a window function partitioned by patient and ordered by month. For the first two months, average the available months.
  4. Return patient_id, month_start, monthly_orders, and rolling_three_month_avg, ordered by patient and month.

Schema

patients
ColumnTypeDescription
patient_idPKINTEGERUnique patient identifier
patient_nameVARCHAR(100)Patient display name
genomic_test_orders
ColumnTypeDescription
order_idPKINTEGERUnique genomic test order identifier
patient_idINTEGERPatient associated with the order
ordered_atTIMESTAMPTimestamp when the order was created
order_statusVARCHAR(20)Current order status
Tablespatientsgenomic_test_orders
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results