Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Average Hospital Stay Duration

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

Your question is Average Hospital Stay Duration. Start with the requirements and the one table 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

MediCore Hospital wants to measure the typical length of stay for completed patient visits. Write a SQL query to calculate the average time between admission and discharge using a single table.

Requirements

  1. Use only rows where discharge_time is not NULL
  2. Return the average stay duration in hours, rounded to 2 decimal places

Schema

admissions
ColumnTypeDescription
admission_idPKINTUnique admission record ID
patient_nameVARCHAR(100)Patient full name
departmentVARCHAR(50)Hospital department handling the admission
admission_timeTIMESTAMPTimestamp when the patient was admitted
discharge_timeTIMESTAMPTimestamp when the patient was discharged; NULL for active stays
Tablesadmissions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results