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