title: SQL: selecting rows where column value changed from previous row
body: <p>Let's say I have this (MySQL) database, sorted by increasing timestamp:</p>
  
  <pre><code>Timestamp   System StatusA StatusB 
  2011-01-01     A      Ok     Ok      
  2011-01-02     B      Ok     Ok     
  2011-01-03     A     Fail   Fail     
  2011-01-04     B      Ok    Fail     
  2011-01-05     A     Fail    Ok      
  2011-01-06     A      Ok     Ok      
  2011-01-07     B     Fail   Fail    
  </code></pre>
  
  <p>How do I select the rows where StatusA changed from the previous row for that system? StatusB doesn't matter (I show it in this question only to illustrate that there may be many consecutive rows for each system where StatusA doesn't change). In the example above, the query should return the rows 2011-01-03 (StatusA changed between 2011-01-01 and 2011-01-03 for SystemA), 2011-01-06, 2011-01-07.</p>
  
  <p>The query should execute quickly with the table having tens of thousands of records.</p>
  
  <p>Thanks</p>