Count for consecutive records

Posted by Nai on Stack Overflow See other posts from Stack Overflow or by Nai
Published on 2010-03-24T20:30:44Z Indexed on 2010/03/24 20:33 UTC
Read the original article Hit count: 229

Filed under:
|

I have a table as follows

> RowID SessionID     EventID   IPAddress   RequestedURL    Date
> 1 m2jqyc45gtjmvb55dc4dg   1   82.23.149.238   Start           24/03/2010 19:52
> 2 m2jqyc45gtjmvb55dc4dg   1   82.23.149.238   BuyNow          24/03/2010 19:52
> 3 m2jqyc45gtjmvb55dc4dg   28  82.23.149.238   Clicked OK  24/03/2010 19:52
> 4 m2jqyc45gtjmvb55dc4dg   1   82.23.149.238   ProductPage 24/03/2010 19:52
> 5 m2jqyc45gtjmvb55dc4dg   1   82.23.149.238   Home            24/03/2010 19:56
> 6 m2jqyc45gtjmvb55dc4dg   1   82.23.149.238   ProductPage 24/03/2010 19:56
> 7 m2jqyc45gtjmvb55dc4dg   1   82.23.149.238   BuyNow          24/03/2010 19:56
> 8 m2jqyc45gtjmvb55dc4dg   28  82.23.149.238   Clicked OK  24/03/2010 19:56
> 9 m2jqyc45gtjmvb55dc4dg   1   82.23.149.238   Home            24/03/2010 19:56

How do I write a query that does a count whenever the rows BuyNow and Clicked OK have been recorded consecutively. For example, the dataset above, the return count should be 2.

© Stack Overflow or respective owner

Related posts about t-sql

Related posts about sql-server