Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Debugging a Complex SQL Issue

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

Your question is Debugging a Complex SQL Issue. Start with the requirements and the three 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

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
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results