Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Join Two Tables in SQL

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

Your question is Join Two Tables in SQL. 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

HCA Healthcare needs a January 2025 operational summary showing completed patient encounters for every facility, including facilities with no qualifying encounters. Write a PostgreSQL query joining facilities to patient_encounters.

Requirements

  1. Return every facility, even when it has no completed encounters during January 2025.
  2. Count completed encounters and calculate the average charge amount for that period.
  3. Sort results by facility name in ascending order.
  4. Apply encounter filters without removing facilities that have no qualifying encounters.

Schema

facilities
ColumnTypeDescription
facility_idPKINTEGERUnique HCA Healthcare facility identifier
facility_nameVARCHAR(150)Facility name
cityVARCHAR(80)Facility city
state_codeCHAR(2)Two-letter state code
patient_encounters
ColumnTypeDescription
encounter_idPKINTEGERUnique encounter identifier
facility_idINTEGERAssociated facility identifier
encounter_dateDATEDate of the encounter
statusVARCHAR(20)Encounter status
encounter_typeVARCHAR(30)Encounter classification
charge_amountNUMERIC(10,2)Recorded encounter charge
Tablesfacilitiespatient_encounters
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results