|
Here is my table: 5 rows of sample data (from a total of 15.5K rows): Symbol varies, PctGain maybe pos/neg and DSeqkey is an arbitrary unique integer representing each trading day. I want SQL that will return the number of DSeqKeys for the longest contiguous sequence of negative PctGains.
(comments are locked)
|
|
Test this on your data, I can make adjustments as needed. +1 for object names :)
Nov 28 '11 at 11:12 PM
Fatherjack ♦♦
(comments are locked)
|
|
Take a look at the logic here (http://msdn.microsoft.com/en-us/library/aa175780(v=sql.80).aspx) and see if you can apply it to your problem. If not then come on back and tell us how far you got and we'll help further. I am actively digesting this article thank you.
Nov 26 '11 at 01:33 PM
Frank Zappa
(comments are locked)
|
|
This will give you the answer. I can modify it to tell you where the start of the sequence was if you wish!
(comments are locked)
|


Do you want the longest sequence for each symbol, or should we ignore the symbol? Second, do you simply want the number of DSeqKeys or do you actually want to return the DSeqKeys that make up the sequence?
Thank you Scott - For each Symbol would be ideal. Just the number of DSeqKeys is fine.