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.
A denormalized analytics table stores a copy of attributes from a source table (for example orders_flat carries customer_email and customer_signup_date copied from customers). Design a SQL check that detects when those denormalized attributes have gone stale relative to the current source row, or when a foreign key still resolves but the referenced dimension row has itself become out of date (surrogate-key drift). Produce a reconciliation report of affected rows.
Design a single SQL query that produces a per-column data-quality summary for a table: total row count, null count and percentage, distinct count, min/max where applicable, and a count of invalid values by whatever rule applies (for example, negative amounts). Discuss how you would extend this into a reusable audit pattern that runs against many tables, and how you might roll several such signals into one normalized 0-100 data-quality score per table.
You are responsible for validating an orders table after every nightly ETL load. List and implement, as SQL, at least five basic checks you would run: row-count reconciliation against a prior baseline, null rate on required fields, min/max of a date column, referential integrity to the customers table, and a distinct-count check on the primary key. Structure the output as one row per check with the check name, expected value, observed value, and a PASS/FAIL status.
A categorical column (for example gender, country, or a status field) has accumulated inconsistent values across sources: mixed case, abbreviations, and synonyms that all mean the same thing. Write SQL that normalizes the observed values to a canonical set using a mapping table, and produces a report of any UNMAPPED values so the mapping table can be extended over time. Where would you store that mapping for maintainability?
You suspect a cumulative divergence has been building between two systems tracking the same numbers over time. Write SQL that computes the running (cumulative) difference day by day and finds the FIRST date at which the cumulative divergence crosses a given threshold (percentage or absolute), so you can narrow an investigation to a specific starting point rather than re-checking the whole history.
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.