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.
Write a query that detects a material shift in a categorical column's distribution between two time periods (for example this month versus the prior six months, or this week versus last week): compute the percentage share per category in each period, the relative change, and flag categories whose share changed by more than a threshold (for example 10 percentage points). Discuss how you would avoid false alarms from categories with very few observations, and how you'd handle a category that appears in only one of the two periods.
A table has a JSON payload column that is expected to contain certain required keys (for example user_id and order_value). Write SQL that returns the rows where a required key is missing, or where a value that should be numeric can't be safely interpreted as one, along with example failing rows and counts.
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.
Write a query that validates a numeric or categorical column against a defined domain: for example, a percentage of sensor readings expected to fall within a physical range, an amount expected to be non-negative, or a currency code expected to be one of a small allowed set. Return the violating rows and a count per rule, and discuss how you would choose the range thresholds and how large a sample you'd need to trust the result.
Write a query that compares two schema snapshots of the same table (taken at different times) and reports which columns were added or dropped, and the null rate for each shared column in both snapshots, so you can detect schema drift early. Show how you would run this against information_schema (or an equivalent) in practice, including detecting when a column disappears or its type/nullability changes.
Unlock Full Question Bank
Get access to all 23 SQL-Based Data Cleaning and Anomaly Detection interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.