In SQL Server 2005 I have a table that stores incoming and outgoing patients in a hospital.
Table data stores are: patient’s full name, date of admission, date of discharge, and the cause of the entrance to the hospital.
What I need is a query to show me the number of patients discharged and re-enter within 72 hours for the same cause.
the table structure is:
CREATE TABLE hospital(
patient varchar(50),
in datetime,
out datetime,
reason_id int
);
This is the query:
SELECT DISTINCT H1.PATIENT
FROM HOSPITAL H1
INNER JOIN (SELECT * FROM HOSPITAL) H2 ON DATEDIFF(HOUR,H1.IN,H2.OUT) < 72
1 Answer