Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started
Compare Latest Completed Runs by Subject
00:00
5 left

Compare Latest Completed Runs by Subject

MediumSQL · PostgreSQL

Problem

How would you approach a take-home project in R or Python to deliver a clear analysis and results?

For this SQL-focused exercise, use the provided analysis-run, subject, and observation data. Return a reproducible comparison of the two latest completed runs, including coverage, metric changes, data-quality indicators, and an impact grouping.

Output

  1. One row per subject included in either selected run
  2. Columns: subject_id, subject_name, latest_value, prior_value, change_value, latest_quality_flags, impact_quartile, and result_status
  3. Include subjects missing from one run and identify quality or coverage issues
  4. Order by impact_quartile, then subject_id

Output details

  • Select the two completed runs by run_started_at descending, breaking ties by run_id descending.
  • Include every subject from subjects, including subjects absent from both selected runs.
  • Average observations per subject-run, round to two decimals, and list distinct non-null quality flags alphabetically separated by , ; otherwise return NULL.
  • Treat zero values as present, and classify statuses in precedence order: missing_latest, missing_prior, quality_review when flags contain warning, declined for negative changes, otherwise improved_or_stable.
  • Assign four impact_quartile buckets by absolute change descending, place NULL changes last, and break ties by subject_id ascending.
  • Order the final rows by impact_quartile ascending, then subject_id ascending.

Schema

analysis_runs
ColumnTypeDescription
run_idPKINTUnique analysis run identifier
run_started_atTIMESTAMPRun start timestamp
statusVARCHAR(20)Run completion status
run_labelVARCHAR(50)Optional human-readable run label
subjects
ColumnTypeDescription
subject_idPKINTUnique subject identifier
subject_nameVARCHAR(80)Subject display name
subject_groupVARCHAR(40)Optional subject grouping
observations
ColumnTypeDescription
observation_idPKINTUnique observation identifier
run_idINTRelated analysis run
subject_idINTRelated subject
metric_valueNUMERIC(10,2)Observed metric value
quality_flagVARCHAR(20)Optional observation quality indicator
Tablesanalysis_runssubjectsobservations
Interviewer

Your question is Compare Latest Completed Runs by Subject. 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
Sign up free to run your codeLog inLn 1
Run your query to see results here.