连续出勤N天的记录

select   emp_id,name,min(cdatetime),max(cdatetime)
from   (select   *,
(select   count(*) 'ii'  
  from   vwDO_Test   b   where   b.emp_id=a.emp_id  
  and   b.cdatetime <=a.cdatetime)ii   from   vwDO_Test   a)c
group   by   emp_id,name,DATEADD(day,-c.ii,cdatetime)   having   count(*)> =7
order by emp_id
原文地址:https://www.cnblogs.com/Doitman/p/1998697.html