title: Get variance and standard deviation of two numbers in two different rows/columns with sqlite / PHP
body: <p>I have a SQLite Database with the following structure:</p>
  
  <pre><code>rowid       ID                  startTimestamp   endTimestamp   subject
  1           00:50:c2:63:10:1a   1000             1090           entrance
  2           00:50:c2:63:10:1a   1100             1270           entrance
  3           00:50:c2:63:10:1a   1300             1310           door1
  4           00:50:c2:63:10:1a   1370             1400           entrance
  .
  .
  .
  </code></pre>
  
  <p>I have prepared a sqlfiddle here: <a href="http://sqlfiddle.com/#!2/fe8c6/2" rel="nofollow">http://sqlfiddle.com/#!2/fe8c6/2</a></p>
  
  <p>With this SQL-Query i can get the average differences between the endTime and the startTime between one row and the following row, sorted by subject and ID:</p>
  
  <pre><code>SELECT
      id,
      ( MAX(endtimestamp) - MIN(startTimestamp)
      - SUM(endtimestamp-startTimestamp)
      ) / (COUNT(*)-1) AS averageDifference
  FROM
      table1
  WHERE ID = '00:50:c2:63:10:1a'
  AND subject = 'entrance'
  GROUP BY id;
  </code></pre>
  
  <p>My problem: To calcute the average value is no problem, that does this query. But how can i 
  get the standard deviation and the variance of this values? </p>