title: Efficient way to calculate the time consumed by each user on a system
body: <p>Good day all, I have a mySQL table that looks like this:</p>
  
  <pre><code>|Id |username           |timestamp              |timestring     |
  +---+-------------------+-----------------------+---------------+
  |4  |user1              |2016-02-11 11:50:21    |20160211115021 |
  |3  |user3              |2015-12-04 15:55:46    |20151204155546 |
  |2  |user2              |2015-12-03 19:54:48    |20151203195448 |
  |1  |user1              |2015-11-27 10:24:30    |20151127102430 |
  +---+-------------------+-----------------------+---------------+
  </code></pre>
  
  <p>And this shows the access logs on a mutual exclusion panel (only one person each time can stay logged in).
  What I'd like to do is to have some statistics, most of them are quite straight forward, but I have difficulties in calculating the time spent on the panel, I would like to know for each user, how much time he/she has "blocked" the system.</p>
  
  <p>actually, I'm creating an array of usernames, in which I progressively sum all the seconds the user have from the "next" one (taken by id).</p>
  
  <p>I feel this is very time consuming for the system, and I would like to have a more efficient way to do it, is there a way to obtain this using mySQL, or is better to build a new table in which I simply store all the usernames and add the time from time to time? Or is better to use PHP?</p>
  
  <p>I must consider that the mySQL is a shared one, so my resources aren't limitless.</p>