Find the longest hospital stay of each patient. Return patient_id, admission_id and the number of days stayed (length_of_stay). If the patient has not been discharged (discharge_dateIS NULL), count up to the current date. Sort by patient ID ascending, then by length of stay in descending order. If there are two or more hospital stays of equal duration, select the most recent discharge episode.
Expected Output
Query Editor
User Output Ready
Execute a query or press Ctrl+Enter to view results...
Databases & Questions
Hint
Use the current date when there is no discharge date, then keep the longest stay for each patient.