SQL-Based Data Cleaning and Anomaly Detection Questions

Using SQL to profile, clean, and validate data: detecting duplicates, nulls, outliers, and referential-integrity breaks; writing production-safe diagnostic queries; and root-cause debugging of missing or incorrect data. Covers anomaly-detection queries and data cleaning for analytics. The hands-on SQL data-quality skill.

MediumTechnical
28 practiced

Write a query that flags outliers in a numeric column using the IQR (interquartile range) method: compute Q1 and Q3 (for example with PERCENTILE_CONT), derive the IQR, and flag values outside [Q1 - 1.5*IQR, Q3 + 1.5*IQR]. Show how you would compute this PER CATEGORY (for example per country or per product) rather than globally, and discuss how you would handle a category with very few rows where the IQR is not a reliable signal.

HardTechnical
33 practiced

Given a table of timestamped events per entity (for example sensor readings per sensor, or activity dates per customer), write an efficient SQL query using LAG/LEAD or window functions that identifies gaps between consecutive events longer than an expected interval, and returns the gap start, end, and duration per entity. Discuss how this scales when there are millions of distinct entities.

HardTechnical
37 practiced

You ingest semi-structured JSON payloads where different records use inconsistent sets of keys. Write a single-pass SQL query that infers a schema from the data: list every top-level key observed, its inferred type, the count of non-null occurrences, and a small sample of values, so you can understand what's actually in the payload before designing a stricter schema.

HardTechnical
25 practiced

A key business metric suddenly looks wrong: it dropped or spiked sharply overnight. Walk through the sequence of SQL queries you would run, in order, to determine whether the cause is a pipeline/join problem, a filtering bug, an instrumentation issue, or a genuine business change. Be concrete about what each query checks and what result would point you toward which cause.

HardTechnical
37 practiced

Write a query that computes the daily null rate for a required column, grouped by source, over the last 60 days, and flags days where that day's null rate is a statistical outlier relative to a trailing baseline (mean plus three standard deviations over the preceding 28 days) rather than against a fixed threshold. Discuss how you'd avoid false positives when the sample size on a given day is small.

Unlock Full Question Bank

Get access to all 23 SQL-Based Data Cleaning and Anomaly Detection interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.