Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Join Patients and Appointments

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

Your question is Join Patients and Appointments. 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

The University of Kansas Medical Center needs a patient appointment summary for operational reporting. Write a PostgreSQL query that joins the patient and appointment data and returns one row for every patient, including patients who have never had an appointment.

Requirements

  1. Join patients to appointments using the patient identifier.
  2. Calculate the number of appointments for each patient.
  3. Return patients with zero appointments, and sort by appointment count descending, then patient name ascending.

Schema

patients
ColumnTypeDescription
patient_idPKINTEGERUnique patient identifier
patient_nameVARCHAR(100)Patient display name
emailVARCHAR(255)Contact email when available
appointments
ColumnTypeDescription
appointment_idPKINTEGERUnique appointment identifier
patient_idINTEGERPatient associated with the appointment
appointment_dateDATEScheduled appointment date
statusVARCHAR(30)Appointment status
Tablespatientsappointments
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results