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.
Standard deviation-based outlier detection breaks down when the underlying data is skewed, because the mean and standard deviation themselves get pulled by the outliers. Write a SQL-based robust alternative using the median and median absolute deviation (MAD), computed with window functions over a rolling window, and explain the threshold rule you'd use to call a day anomalous.
A key business metric suddenly looks wrong: it dropped or spiked sharply overnight. Walk through the sequence of SQL queries you would run, in order, to determine whether the cause is a pipeline/join problem, a filtering bug, an instrumentation issue, or a genuine business change. Be concrete about what each query checks and what result would point you toward which cause.
You need to reconcile financial transactions recorded across two or three related systems (for example payments, invoices, and a general ledger) where amounts may be in different currencies, rounding conventions differ, and each source can lag the others by a different amount of time. Propose a SQL-based reconciliation approach: matching by transaction ID where present, falling back to a tolerance-aware match on amount, date, and counterpart when it isn't, applying historical FX conversion, and reporting unmatched records and the summary deltas.
Design a checksum-based validation to detect mismatches between a source table and its warehouse copy without comparing every column value directly: compute a row-level hash (for example MD5 over a canonicalized set of columns) and a per-day table-level checksum, and explain how you handle column ordering, NULLs, and floating-point values so the checksum is deterministic and comparable across environments.
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.