title: How to write SQL queries to calculate aggregate server up-time?
body: <p>I have a requirement in SQL where I have data of a server start stop time on daily basis for one month. I need the result where it should calculate the first start time of the day, last stop time of the day, total time server was started in a day on daily basis and for servers.</p>
  
  <p>Table is like below and  expected output is also given.</p>
  
  <p>Table:</p>
  
  <pre><code>Date &amp; Time           Reader ServerID
  3/14/2016 6:36:20 AM    ON  123
  3/14/2016 6:58:45 AM    OFF 123
  3/14/2016 8:06:19 AM    ON  123
  3/14/2016 9:32:48 AM    OFF 123
  3/15/16 6:00:00 AM      ON  123
  3/15/16 6:01:00 AM      OFF 123
  3/14/2016 9:46 AM       ON  124
  3/14/2016 10:01 AM      OFF 124
  3/14/16 11:01 AM        ON  124
  3/14/16 12:01 PM        OFF 124
  </code></pre>
  
  <p>Expected output</p>
  
  <pre><code>UserID   FirstIN   Last Out  TotalInTime (min)    Date
  123       6:00      09:32      86         3/14
  123       06:00     06:01      1         3/15
  124       9:46      12:01      75         3/14 
  </code></pre>