Task
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
- Use only rows where
discharge_time is not NULL
- Return the average stay duration in hours, rounded to 2 decimal places
Table Definition
admissions
| Column | Type | Description |
|---|
| admission_id | INT | Unique admission record ID |
| patient_name | VARCHAR(100) | Patient name |
| department | VARCHAR(50) | Hospital department |
| admission_time | TIMESTAMP | Time the patient was admitted |
| discharge_time | TIMESTAMP | Time the patient was discharged; may be NULL for active stays |
Sample Data
| admission_id | patient_name | department | admission_time | discharge_time |
|---|
| 1 | Alice Chen | Cardiology | 2024-03-01 08:00:00 | 2024-03-03 10:00:00 |
| 2 | Brian Lee | Neurology | 2024-03-02 14:30:00 | 2024-03-02 20:30:00 |
| 3 | Carla Gomez | Orthopedics | 2024-03-04 09:15:00 | NULL |
| 4 | David Park | Cardiology | 2024-03-05 11:00:00 | 2024-03-06 11:00:00 |
| 5 | Emma Davis | Pediatrics | 2024-03-01 23:00:00 | 2024-03-02 05:00:00 |
| 6 | Farah Khan | Neurology | 2024-03-06 07:45:00 | 2024-03-08 07:45:00 |
Expected Output