How to Calculate longest streak in SQL?
Posted
by VJ
on Stack Overflow
See other posts from Stack Overflow
or by VJ
Published on 2010-06-15T22:38:03Z
Indexed on
2010/06/15
22:42 UTC
Read the original article
Hit count: 194
tsql
|sql-server-2008
I have
EMPLOYEE-ID,DATE,IsPresent
I want to calculate longest streak for a employee presence.The Present bit will be false for days he didnt come..So I want to calculate the longest number of days he came to office for consecutive dates..I have the Date column field is unique...So I tried this way -
Select Id,Count(*) from Employee where IsPresent=1
But the above doesnt work...Can anyone guide me towards how I can calculate streak for this?....I am sure people have come across this...I tried searching online but...didnt understand it well...please help me out..
© Stack Overflow or respective owner