A small data quality test suite as one query
The task
The data team runs these four checks on the HR tables every night. Each check counts the rows that break a rule:
department_id_not_null: employees whosedepartment_idisNULL.manager_exists: employees whosemanager_idis notNULLbut matches noemployee_idinemployees.rating_between_1_and_5: rows inreviewswhereratingis below 1 or above 5.termination_not_before_hire: employees whosetermination_dateis before theirhire_date. Leaving on the hire day is allowed.
Return one row for each check, with test_name (the name above) and failing_rows (the count, 0 when the check passes). Sort by test_name.
Expected output
test_namefailing_rows- Sorted by test_name ascending.
- Checked on the sample and on 2 hidden datasets. How grading works
Tables People team · click a name to insert it
departments7 rows in the sample
One row per department. Key: department_id.
| int | Unique id. | |
| text | Name. | |
| text | Main office city. |
employees120 rows in the sample
Everyone who has worked here, including people who left. Key: employee_id.
| int | Unique id. | |
| text | Name. | |
| int | Department. NULL for a few people between teams. | |
| int | Their manager (an employee_id). NULL for the CEO. | |
| text | Title. | |
| date | First day. | |
| date | Last day. NULL while employed. | |
| numeric(10,2) | Current (or final) yearly salary, USD. |
salary_changes367 rows in the sample
Every salary someone has had, from the day it applied. Key: employee_id, effective_on.
| int | The employee. | |
| date | First day of this salary. | |
| numeric(10,2) | Yearly salary, USD. |
reviews301 rows in the sample
Year-end review ratings. Key: employee_id, review_year.
| int | The employee. | |
| int | Year reviewed. | |
| int | 1 (low) to 5 (high). |
Related questions
- Data test for direct buyers with no usable emaileasy
- Reconcile active subscriptions against February invoicesmedium
- Salary validity ranges built with LEADmedium
- Active accounts and seats per day from subscription datesmedium
- Agent by month fact table of tickets created and resolvedmedium
- Campaign by day fact table with cumulative spendhard
Loading the editor and PostgreSQL
Loading the editor and PostgreSQL