Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Optimizing Multi-Terabyte SQL
00:00
5 left

Optimizing Multi-Terabyte SQL

HardSQL · PostgreSQL

Problem

How do you optimize a slow-running SQL query that joins multi-terabyte R&D data repositories with complex aggregations?

Write a PostgreSQL query that returns study-level metrics for completed studies that started in 2025. The query should exclude invalid assay results and assay measurements outside calendar year 2025 while preserving eligible studies with no matching experiments or results.

Output

  1. One row per eligible study, with study_code, experiment_count, compound_count, valid_assay_count, avg_measured_value, and max_toxicity_score
  2. Include eligible studies with zero matching results, using zero counts and NULL averages or maximums where appropriate
  3. Order by study_code ascending

Schema

rd_studies
ColumnTypeDescription
study_idPKINTR&D study identifier
study_codeVARCHAR(20)Human-readable study code
therapeutic_areaVARCHAR(40)Therapeutic area
statusVARCHAR(20)Study lifecycle status
start_dateDATEStudy start date
rd_experiments
ColumnTypeDescription
experiment_idPKINTExperiment identifier
study_idINTAssociated study
compound_idINTTested compound, when assigned
experiment_dateDATEExperiment execution date
repository_nameVARCHAR(40)Source R&D repository
assay_results
ColumnTypeDescription
assay_result_idPKINTAssay result identifier
experiment_idINTAssociated experiment
assay_nameVARCHAR(40)Assay name
measured_valueNUMERIC(12,4)Measured assay value
toxicity_scoreNUMERIC(8,4)Toxicity score
result_statusVARCHAR(20)Result validation status
measured_atDATEMeasurement date
Tablesrd_studiesrd_experimentsassay_results
Interviewer

Your question is Optimizing Multi-Terabyte SQL. Start with the requirements and the three tables in the Question tab.

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.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.