SQL-Based Data Validation and Anomaly Detection Questions
Techniques for validating data quality and detecting anomalies using SQL: identifying nulls and missing values, finding duplicates and orphan records, range checks, sanity checks across aggregates, distribution checks, outlier detection heuristics, reconciliation queries across systems, and building SQL based alerts and integrity checks. Includes strategies for writing repeatable validation queries, comparing row counts and sums across pipelines, and documenting assumptions for investigative analysis.
EasyTechnical
29 practiced
Write a SQL query to validate numeric ranges: for a table `measurements(sensor_id, measured_at, temperature_c)` check that 99.9% of readings are between -50 and 150 degrees and return sensors that violate this rule. Provide the SQL and explain how to choose the thresholds and sample sizes.
EasyTechnical
27 practiced
Write a SQL query to detect sudden changes in distribution between two months for a categorical column `payment_method`. Report the percentage point change per category and flag categories with absolute change > 10 percentage points. Assume table `payments(payment_id, dt, payment_method)`.
MediumTechnical
25 practiced
Design a strategy to automatically detect schema drift where a column's data type or nullability changes in source feeds. Describe checks, notification paths, and how to handle silent type coercions that can corrupt downstream aggregations.
MediumTechnical
33 practiced
Write a SQL query to find groups of rows with the same natural key but conflicting attribute values. Example: `customers(natural_key, email, phone, address)`. Return natural_key, count, array_agg(distinct email) as emails, array_agg(distinct phone) as phones and filter where count > 1 and attributes disagree. Explain how to use this in validation.
MediumTechnical
36 practiced
Write a SQL query that detects orphan child rows produced by a late upstream delete: `events(event_id, user_id, ts)` and `users(user_id)`. The ETL that deletes users sometimes runs after events are ingested. Produce a query that identifies events whose user_id became deleted within a given timeframe and classify them as 'probable-orphan' vs 'definitive-orphan' given a configurable grace period.
Unlock Full Question Bank
Get access to hundreds of SQL-Based Data Validation and Anomaly Detection interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.