Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL for Equipment Accountability
00:00
5 left

SQL for Equipment Accountability

MediumSQL · PostgreSQL

Problem

Write a SQL query to track equipment accountability by comparing government-furnished equipment checkouts, returns, and missing items across multiple exercise dates.

Use the supplied exercise, equipment, and transaction data. Treat an item as missing when it was checked out for an exercise but has not been returned for that exercise.

Output

  1. One row per exercise date, including dates with no transactions.
  2. Columns: exercise_date, exercise_name, checked_out_count, returned_count, missing_count, and missing_equipment_codes.
  3. Show missing equipment codes as a comma-separated, alphabetically ordered string, or an empty string when none are missing.
  4. Order by exercise_date ascending.

Schema

exercises
ColumnTypeDescription
exercise_idPKINTUnique exercise identifier
exercise_nameVARCHAR(100)Exercise name
exercise_dateDATEDate of the exercise
notesTEXTOptional exercise notes
equipment
ColumnTypeDescription
equipment_idPKINTUnique equipment identifier
equipment_codeVARCHAR(30)Readable equipment accountability code
equipment_typeVARCHAR(50)Equipment category
serial_numberVARCHAR(50)Manufacturer serial number
equipment_transactions
ColumnTypeDescription
transaction_idPKINTUnique transaction identifier
exercise_idINTExercise associated with the transaction
equipment_idINTEquipment involved in the transaction
event_typeVARCHAR(20)Transaction type, such as CHECKOUT or RETURN
event_dateDATEDate of the transaction
returned_byVARCHAR(100)Person recording a return
Tablesexercisesequipmentequipment_transactions
Interviewer

Your question is SQL for Equipment Accountability. 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.