select er.*
from (select er.*,
lead(workday, 4) over (partition by staffid order by workday) as workday_4
from dbo.EmployeeRecords er
where reasonId = 3 and isPaid = 1
) er
where workday_4 = dateadd(day, 4, workday);
select * from dbo.EmployeeRecords
where staffid in
(
select staffid
from
(
select staffid, count(staffid) cnt rownum
from dbo.EmployeeRecords
where reasonId = 3 and isPaid = 1
group by staffid
)t
where t.cnt>=5
)
2条答案
按热度按时间k3fezbri1#
最简单的方法是
lead()
--假设你每天只有不超过一行,并且没有间隔workday
列。所以,要获得这样的假期的第一天:“4”比“5”小一个,因为当前日期已计为一天。
如果你中间有周末,需要考虑这些,那么5天就是一周。您可以使用:
因为5天等于一周,所以这很容易奏效。否则你需要考虑到一周中的哪一天。
jdg4fx2g2#
使用带有count运算符的子查询尝试下面的查询