title: SQL Query - How to get count where current row values in between previous rows
body: <p>So, I have to calculate total <code>Type</code> A where <code>From</code> &amp; <code>To</code> in between <code>From</code> &amp; <code>To</code> <code>Type</code> B based on <code>ID</code>.
  I can't describe it in good words, so this is the example and my expected result (Column <code>Count</code>) :</p>
  <pre><code>ID  | Type | From | To | Count
  -------------------------------
  100 | A    | 10   | 14 | 
  100 | A    | 16   | 18 | 
  100 | B    | 12   | 14 | 1
  100 | B    | 11   | 13 | 1
  100 | B    | 17   | 18 | 1
  120 | A    | 5    | 10 | 
  120 | A    | 12   | 14 | 
  120 | A    | 18   | 20 | 
  120 | A    | 18   | 20 | 
  120 | A    | 22   | 24 | 
  120 | B    | 30   | 32 | 0
  120 | B    | 19   | 20 | 2
  120 | B    | 10   | 14 | 1
  </code></pre>
  <p>Anybody can help ? I'm expecting something similar like COUNT OVER or RANK OVER without GROUP BY because the table above is not original table, its from another subquery..</p>