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 reconciles a source table against its downstream warehouse counterpart on a daily basis: for each day, compute the row counts (and/or sums) on both sides, the absolute and percentage difference, and flag any day where the difference exceeds a tolerance (for example greater than 1%). Discuss how you would schedule this, alert on it, and store the reconciliation history for trend analysis.
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.
Write a single SQL query over a transactions table that computes BOTH a z-score flag (more than 3 standard deviations from the mean) and an IQR flag (outside Q1 - 1.5*IQR / Q3 + 1.5*IQR) for the same numeric column, in one pass, so the two methods can be compared side by side on the same data.
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.
Given a table of daily per-entity metrics (for example, a metric value per product per day), write a query that finds entities with missing expected data points over a recent window (for example, the last 90 days), returning each entity and a count of its missing dates. State your assumptions about the expected date range and any business calendar effects.
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.