title: SQL to detect "sequence break"
body: <p>I have data in which incremental sequence is broken somewhere, maybe multiple times.
  E.g. (2,3,4,5,6,8,10).</p>
  
  <p>I want to get:</p>
  
  <ol>
  <li>the first "broken" place (6 is the last good in the example)</li>
  <li>the number of "broken" places (2 times, on 7 and 9)</li>
  </ol>
  
  <p>using SQL (preferably general, which works on oracle and mysql and other sql platforms).</p>
  
  <p>Using sequences or auto_increment are platform-specific.</p>
  
  <p>I tried self-join constructions like </p>
  
  <pre><code>select curr.id+1 as first_fail from junk as prev
  join junk as curr 
  on (prev.id+1 = curr.id) 
  order by curr.id desc limit 1;
  </code></pre>
  
  <p>(<a href="http://sqlfiddle.com/#!9/bae781/4/0" rel="nofollow">http://sqlfiddle.com/#!9/bae781/4/0</a>)
  but it seems ugly, and can't get the number of "broken" places this way.</p>