Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL for Compliance Extraction

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is SQL for Compliance Extraction. Start with the requirements and the two tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

ERM Digital stores environmental, health, safety, and regulatory obligations across client facilities. Write a PostgreSQL query that produces an operational extract of active compliance records requiring attention by June 30, 2025.

Requirements

  1. Return records with status Open or Overdue whose due date is on or before June 30, 2025, or whose due date is missing.
  2. Use a LEFT JOIN so records remain visible when their facility or facility attributes are missing.
  3. Replace missing facility names, regions, responsible people, and due dates with readable labels. Classify each record as Overdue, Due by cutoff, or Missing due date.
  4. Order records by due date ascending, placing records without due dates last.

Schema

compliance_records
ColumnTypeDescription
record_idPKINTUnique compliance record identifier
facility_idINTReferenced facility identifier
requirement_nameVARCHAR(120)Name of the compliance obligation
statusVARCHAR(20)Current compliance record status
due_dateDATERequired completion date
responsible_personVARCHAR(100)Assigned compliance owner
created_dateDATEDate the record was created
facilities
ColumnTypeDescription
facility_idPKINTUnique facility identifier
facility_nameVARCHAR(120)Facility display name
regionVARCHAR(60)Operating region
erm_site_codeVARCHAR(30)ERM Digital site code
Tablescompliance_recordsfacilities
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results