I have table
id year month day
1 2012 1 1
2 2012 1 2
3 2012 1 3
4 2012 1 4
5 2012 1 5
6 2012 1 7
7 2012 1 8
8 2012 1 9
9 2012 1 10
10 2012 1 11
from the above table i want to generate the following output when count of id reaches the
multiple of 5
day_start day_end
1 5
5 11
This will work in SQL Server. Using the
row_numberrather than theidfield value will prevent errors if you delete rows and the sequence of ids is no longer complete.Note: I’m basing this answer on the fact that you said the “count of id” reaches 5, and not “the value of id”. Which to me means “every 5 records, regardless of the id value”. If that’s not the case, then leave a comment and I’ll remove this answer, since Mark’s will work fine.