DQ Fail Rate by Table

A medium SQL interview practice problem on DataDriven. Write the query and run it against a real database, with instant feedback.

Domain
SQL
Difficulty
medium
Seniority
L4
Asked in
Airbnb

Problem

Some of our data quality checks record a measured fail percentage; the rest were never scored and leave it blank. For each table, find the share of checks that passed among only the ones carrying a recorded fail percentage.

Pass rates, table by table.

Tables

dq_checks

Columns: check_id INTEGER, tbl_name TEXT, col_name TEXT, rule TEXT, passed INTEGER, fail_pct REAL, run_at TEXT, severity TEXT

dq_checks: 10 of 200 rows
check_idtbl_namecol_namerulepassedfail_pctrun_atseverity
131usersemailunique1NULL2026-02-02 01:00:00high
162productsamountrange1NULL2026-03-03 02:00:00medium
193transactionsstatusformat1NULL2026-04-04 03:00:00low
224eventscreated_atreferential1NULL2026-05-05 04:00:00Critical
255sessionspricefreshness0152026-06-06 05:00:00HIGH
286ad_impressionsregionNot_Null1NULL2026-07-07 06:00:00critical
317ordersuser_idUNIQUE102026-08-08 07:00:00high
348usersemailnot_null1NULL2026-09-09 08:00:00medium
379productsamountunique1NULL2026-01-10 09:00:00low
410transactionsstatusrange0302026-02-11 10:00:00Critical

Expected output

First 5 of 7 rows
tbl_namepass_rate
ad_impressions0
events0
orders0.8571428571428571
products0
sessions0

Worked solution and explanation

What this really tests

This is a filtered average wearing a data-quality costume. The skill being probed: compute each table's pass share, but only across the checks that actually carry a recorded fail_pct. Anyone can write AVG(passed) grouped by tbl_name. The catch is that AVG skips nulls only in its OWN argument, passed, which is fully populated here, so it will happily fold in every unscored check whose fail_pct is null. Leave off WHERE fail_pct IS NOT NULL and you average passed over all the checks instead of the roughly one-third that were scored, and every table's rate drifts toward its whole-table figure (ad_impressions reads 0.79 instead of the correct 0.0) while the query runs without a single error.


Walk the requirements

Step 1: Bound the population to scored checks

WHERE fail_pct IS NOT NULL keeps only the checks that recorded a fail percentage. This is the load-bearing line: about two-thirds of dq_checks were never scored (fail_pct is null) and all of them passed, so leaving them in inflates every table's pass share.

Step 2: Take the pass share per table

GROUP BY tbl_name with AVG(passed). Since passed is 1 for a pass and 0 for a fail, its average over the scored checks is exactly the fraction that passed.


The solution

Pass share over scored checks
SELECT tbl_name, AVG(passed) AS pass_rate
FROM dq_checks
WHERE fail_pct IS NOT NULL
GROUP BY tbl_name

Common follow-up questions