title: Finding rows with consecutive increase in the values of a column
body: <p>I have a sql table that stores the daily prices of stocks. New records are inserted every day after the market closes. I want to find the stocks that have consecutive increases in price.</p>
  
  <p>The table has lots of columns, but this is the relevant subset:</p>
  
  <pre><code>quoteid     stockid      closeprice     createdate
  --------------------------------------------------
      1           1               1       01/01/2012
      2           2              10       01/01/2012
      3           3              15       01/01/2012
  
      4           1               2       01/02/2012
      5           2              11       01/02/2012
      6           3              13       01/02/2012
  
      7           1               5       01/03/2012
      8           2              13       01/03/2012
      9           3              17       01/03/2012
  
     10           1               7       01/04/2012
     11           2              14       01/04/2012
     12           3              18       01/04/2012
  
     13           1               9       01/05/2012
     14           2              11       01/05/2012
     15           3              10       01/05/2012
  </code></pre>
  
  <p>The <code>quoteid</code> column is a primary key.</p>
  
  <p>In the table, the closing price of stock id 1 increases every day. Stock id 3 fluctuates a lot, and the price for stock id 2 fell on the last day.</p>
  
  <p>I am looking for a result like this:</p>
  
  <pre><code>stockid     Consecutive Count (CC)
  ----------------------------------
      1                5
      2                4
  </code></pre>
  
  <p>If you can get output with dates for the consecutive streak, that would even better:</p>
  
  <pre><code>stockid     Consecutive Count (CC)      StartDate      EndDate
  ---------------------------------------------------------------
      1                5                 01/01/2012    01/05/2012
      2                4                 01/01/2012    01/04/2012
  </code></pre>
  
  <p><code>StartDate</code> is when the price started increasing and <code>EndDate</code> is when the bull run actually finished.</p>
  
  <p>I have figured this is not an easy problem. I have looked at other posts here which also deal with this consecutive scenario but they don't fit my needs. If you know any post that is similar to mine, please do let me know.</p>