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.
You need to verify that a column (for example, email) is unique across a table with billions of rows, without a full scan. Describe SQL-based approaches using approximate algorithms such as HyperLogLog / APPROX_COUNT_DISTINCT, bloom filters, or partitioned verification, and discuss the false-positive/false-negative trade-offs and cost implications of each versus an exact count.
Explain how SQL evaluates NULL in comparisons, boolean expressions, and aggregate functions. Why does col = NULL never match, and why do you need IS NULL / IS NOT NULL instead? Show how COALESCE and NULLIF are used to substitute or convert sentinel values, and how COUNT(*), COUNT(column), SUM, and AVG each treat NULLs differently. Also address the related design question: when should missing text be stored as NULL versus an empty string, and why does that choice matter for downstream validation checks?
Write a query that verifies an aggregate invariant holds across related tables: for example, that an order's recorded total_amount equals the sum of its order_items.amount, or that the sum of hourly metric values for a day equals the recorded daily total. Return rows where the invariant is violated beyond a small floating-point tolerance, and discuss the considerations for doing this efficiently over large joins.
Why does reconciliation between a source system and an analytics warehouse matter, and what checks would you routinely run to confirm the two agree? Walk through the investigative process you would follow once a mismatch is detected, from first-pass diagnostics to identifying the likely root cause.
Write a single query that flags several kinds of anomalous groups at once in a financial table: customers with a negative total amount, customers with the same invoice ID appearing more than once, and customers whose average daily amount is many times the median across all customers. Discuss how you would tune the query to reduce false positives.
Unlock Full Question Bank
Get access to all SQL-Based Data Cleaning and Anomaly Detection interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.