Dataford
Interview QuestionsInterview GuidesExperiencesCoachingPricing
Get started
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
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Build my plan
Handling Corrupted Data in Analysis
00:00
5 left

Handling Corrupted Data in Analysis

MediumSQL · PostgreSQL

Problem

How would you handle a situation where your data gets corrupted while working on the analysis? What method or alternative would you use?

Write a PostgreSQL query that compares analysis data with a trusted snapshot, flags discrepancies, and selects a trusted value or backup value when available.

Output

  1. One row per analysis record, ordered by record_id ascending
  2. Columns: record_id, analysis_date, current_metric, data_status, selected_metric
  3. Classify rows as VALID, CORRUPTED, or UNVERIFIED; use the trusted metric when available, otherwise the backup metric, otherwise the current metric

Schema

analysis_data
ColumnTypeDescription
record_idPKINTIdentifier for the analysis record
analysis_dateDATEDate associated with the analysis record
metric_valueDECIMAL(10,2)Metric value currently used in the analysis
source_batchVARCHAR(30)Batch that produced the current analysis value
trusted_snapshot
ColumnTypeDescription
record_idPKINTIdentifier corresponding to an analysis record
metric_valueDECIMAL(10,2)Metric value from the trusted snapshot
snapshot_statusVARCHAR(20)Status of the trusted snapshot row
backup_data
ColumnTypeDescription
record_idPKINTIdentifier corresponding to an analysis record
metric_valueDECIMAL(10,2)Metric value from the backup source
backup_statusVARCHAR(20)Status of the backup row
Tablesanalysis_datatrusted_snapshotbackup_data
Interviewer

Your question is Handling Corrupted Data in Analysis. 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.