Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

Calculating maximum consecutive days.

$
0
0
Hi Guys,
I am new to the forum and am learning SQL and would appreciate any help!! I am on DB2 using QMF SQL. I have a four month data set, each ID will have a 1 or 0 assigned to each date in the four month date span. I need to find the maximum consecutive days where ABSENT = 1. In the below sample set, the answer for ID = X1234 would by be 4 (assuming the rest of the dates are zero). I am stuck and cannot find the right programming, again any help will be greatly appreciated!

DATE ID ABSENT
2012-01-01 X1234 0
2012-01-02 X1234 1
2012-01-03 X1234 0
2012-01-04 X1234 1
2012-01-05 X1234 1
2012-01-06 X1234 1
2012-01-07 X1234 0
2012-01-08 X1234 0
2012-01-09 X1234 1
2012-01-10 X1234 1
2012-01-11 X1234 1
2012-01-12 X1234 1

Viewing all articles
Browse latest Browse all 13329

Trending Articles