InterviewStack.io LogoInterviewStack.io

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.

MediumTechnical
32 practiced

Design a daily scheduled check that counts orphan records for a critical relationship (for example, orders whose customer_id no longer exists in customers), tracks that count as a trend over the last 30 days, and distinguishes a one-off blip from a genuine regression. What producer-side and consumer-side fixes would you propose to prevent new orphans from being created going forward?

MediumTechnical
25 practiced

A raw text column holding dates arrives in multiple formats from different producers (YYYY-MM-DD, MM/DD/YYYY, DD Mon YYYY, and others). Write SQL that attempts to parse each row using the expected formats and returns the rows that fail to parse under any of them, or that parse successfully but land on an impossible date (for example, a signup date in the year 2099). Discuss how you would detect which format is most prevalent to prioritize your parsing order, and how you'd handle genuinely ambiguous dates.

MediumTechnical
30 practiced

Given a transactions table, write a query using window functions that flags a transaction as anomalous for a given user when its amount exceeds that user's own historical mean plus three standard deviations, computed over a trailing window (for example the past 90 or 365 days). Explain how you would handle users with very little transaction history, and how you'd communicate the inevitable false positives to the business stakeholders who see the flagged rows.

MediumTechnical
34 practiced

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.

MediumBehavioral
44 practiced

Tell me about a time you investigated an unexpected anomaly in a production dashboard or metric. Using the STAR format, describe the situation, what you were responsible for, the specific steps you took to validate and investigate the issue (including any SQL checks you ran), and the outcome, including how you documented your assumptions and communicated with stakeholders.

Unlock Full Question Bank

Get access to all SQL-Based Data Cleaning and Anomaly Detection interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.