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
30 practiced

You are working in a data lake or warehouse table with no declared constraints. Design a set of ad-hoc SQL validation queries that would catch the most common defects: invalid email formats, NULLs in required fields, and duplicate primary keys. For each check, show a query that outputs the failing rows and a count, and explain how you would handle known exceptions or a whitelist of accepted edge cases without those obscuring genuine failures.

HardTechnical
37 practiced

You need to validate a data-quality metric (for example, a duplicate rate or a null rate) on a table with tens of billions of rows, where a full scan is too slow or too expensive to run regularly. Describe a statistically sound sampling strategy: how you would choose the sample size and stratification (for example by partition or by day), compute a confidence interval around the estimate, and decide when the sample result is close enough to a threshold that you should escalate to a full scan instead.

MediumTechnical
35 practiced

A subscriptions (or similar effective-dated) table is supposed to have non-overlapping validity periods per key: no two active rows for the same natural key should have overlapping effective_from/effective_to ranges, and the current row's end date should be open (NULL or far in the future). Write SQL that detects violations of this invariant, and separately, show how you would consolidate genuinely adjacent or overlapping ranges into one clean timeline.

MediumTechnical
28 practiced

Compare rule-based anomaly detection (fixed thresholds, IQR, z-score) with a simple machine-learning-based detector (for example isolation forest or a seasonal auto-regressive model) for validating a data pipeline. Discuss the trade-offs in explainability, operational complexity, false-positive rate, and ongoing maintenance burden for a data team, and describe a hybrid strategy that starts rule-based and adds ML only where it's justified.

EasyTechnical
49 practiced

Given a table where a handful of columns are considered critical for downstream analytics, write a query that flags every row where any of those critical columns is NULL, indicates which specific column(s) are NULL for that row, and reports the total count of problematic rows so the magnitude of the issue is clear at a glance.

Unlock Full Question Bank

Get access to all 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.