| Author |
Topic |
|
ucal
Yak Posting Veteran
72 Posts |
Posted - 2010-03-09 : 06:41:11
|
| I have data with the following structure :StudID,ExamID ,Score1,1,201,2,401,3,501,4,101,5,301,6,252,1,502,2,402,3,452,4,672,5,702,6,722,7,653,1,603,2,703,3,604,1,454,2,304,3,65I want to select only records with consecutive increase in Score for each StudID. Increase should be consecutive for 3 or more Score for each StudIDDesired Results:StudID,ExamID ,Score1,1,201,2,401,3,502,3,452,4,672,5,702,6,72 |
|
|
Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts |
Posted - 2010-03-09 : 19:00:27
|
| If 1, 1, 20 is included in the output, why is 2, 2, 40 not included?=======================================Few things are harder to put up with than the annoyance of a good example. (Mark Twain) |
 |
|
|
ucal
Yak Posting Veteran
72 Posts |
Posted - 2010-03-09 : 19:24:52
|
| Good call Bustaz ! 2, 2, 40 should be part of the desired result. |
 |
|
|
Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts |
Posted - 2010-03-09 : 19:40:04
|
| [CODE];with Sequenceasselect a.StudID, a.ExamID, a.Score StartScore, b.Score MiddleScore, c.Score EndScorefrom MyTable ainner join MyTable bon a.StudID = b.StudIDand a.ExamID + 1 = b.ExamIDand a.Score < b.Scoreinner join MyTable con a.StudID = c.StudIDand a.ExamID + 2 = c.ExamIDand b.Score < c.Score)select StudID, ExamID, StartScorefrom Sequenceunion allselect StudID, ExamID + 1, MiddleScorefrom Sequenceunion allselect StudID, ExamID + 2, EndScorefrom Sequence[/CODE]You'll need to eliminate duplicates.=======================================Few things are harder to put up with than the annoyance of a good example. (Mark Twain) |
 |
|
|
ucal
Yak Posting Veteran
72 Posts |
Posted - 2010-03-10 : 21:55:53
|
| Thanks Bustaz, your solution worked for me.Great job !!!! |
 |
|
|
|
|
|