title: sql query - Get the difference time between swipe in - Swipe out for employee
body: <p>I have a table like this</p>
  
  <p>swipe_details</p>
  
  <pre><code>EMPID   EVENT_TYPE   Swipe_time
  1       EN           2012-06-01 12:00
  1       EX           2012-06-01 12:30
  2       EN           2012-06-01 12:50
  1       EN           2012-06-01 13:10
  2       EX           2012-06-01 13:30
  2       EN           2012-06-01 14:00
  2       EX           2012-06-01 19:00
  1       EX           2012-06-01 19:30
  </code></pre>
  
  <p>which basically stores the swipe details of employees (where EN is "Swipe-IN" and EX is "Swipe OUT")</p>
  
  <p><strong>I want to find out the EMPIDs who spend maximum time in the office for a given time frame.
  So my input will be a start time and end time (Ex: 2012-06-01 12:30 and 2012-06-05 18:30).</strong></p>
  
  <p>Please note these 3 conditions as well:</p>
  
  <ol>
  <li><p>There could be employees who have entered office before the time
  frame. In this case we have to consider the swipe in as the
  beginning of the time frame for that employee.</p></li>
  <li><p>Same way for employees who exit after the time frame, the swipe out time would be the end of the time frame.</p></li>
  <li><p>IF there are employees whose swipe in time is less than the time frame and swipe out time is greater than the time frame, then all of
  these empIDs should be shown as the result</p></li>
  </ol>
  
  <p>What is the best way to do it? Is it possible with a single query?</p>