title: MySQL Grouping total
body: <p>I just know the very basics of SQL. I have a database that shows when a person entered an office and when he left.</p>
  
  <p>e.g</p>
  
  <pre><code>Name     Enter                    Exit
  Jack     2014-01-01 01:00:00     2014-01-01 02:00:00
  Sam      2014-01-01 02:00:00     2014-01-01 03:00:00
  Jane     2014-01-01 02:00:00     2014-01-01 03:00:00
  Judy     2014-01-01 03:00:00     2014-01-01 04:00:00
  </code></pre>
  
  <p>What I am trying to do is find out the total number of users that were in the office on an hourly basis, grouped by hours, and maybe grouped by date too, so my result should look like</p>
  
  <pre><code>date           hour   Occupancy
  2014-01-01     1       1
  2014-01-01     2       3
  2014-01-01     3       3
  2014-01-01     4       1
  </code></pre>
  
  <p>****EDIT</p>
  
  <p>I can set the database to only collect hours and discard the minutes, however a person can come in and leave two days after too. So I am looking for something that is not only an hour apart entry and exit.</p>