Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Debugging a Complex SQL Issue
00:00
5 left

Debugging a Complex SQL Issue

HardSQL · PostgreSQL

Problem

Describe a time you used SQL to solve a complex data issue.

For this exercise, use the supplied shift, assignment, and payment tables to demonstrate a reconciliation query. Identify completed assignments where the recorded payment differs from the expected payment, including missing payment records.

Output

  1. One row per completed assignment with a payment discrepancy.
  2. Columns: assignment_id, worker_id, shift_date, expected_payment, recorded_payment, and discrepancy.
  3. Treat a missing payment as zero, order by shift_date ascending and assignment_id ascending.

Schema

shifts
ColumnTypeDescription
shift_idPKINTUnique shift identifier
shift_dateDATEDate of the shift
statusVARCHAR(20)Shift status
hourly_rateNUMERIC(8,2)Expected hourly payment rate
hours_workedNUMERIC(5,2)Hours worked on the shift
assignments
ColumnTypeDescription
assignment_idPKINTUnique assignment identifier
shift_idINTReferenced shift identifier
worker_idINTWorker identifier
payments
ColumnTypeDescription
payment_idPKINTUnique payment record identifier
assignment_idINTReferenced assignment identifier
amountNUMERIC(10,2)Payment amount
Tablesshiftsassignmentspayments
Interviewer

Your question is Debugging a Complex SQL Issue. Start with the requirements and the three tables in the Question tab.

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.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.