2 回答
TA贡献1829条经验 获得超7个赞
select ID
from (select ID,
time,
coun,
lag(coun, 1) over(partition by ID order by time) lag_coun1,
lag(coun, 2) over(partition by ID order by time) lag_coun2,
lag(coun, 3) over(partition by ID order by time) lag_coun3,
lag(coun, 4) over(partition by ID order by time) lag_coun4,
lag(coun, 5) over(partition by ID order by time) lag_coun5,
lag(coun, 6) over(partition by ID order by time) lag_coun6
from (select ID, trunc(add_time, day) time, count(*) coun
from table
where time > 10
and time < 24
group by ID, trunc(add_time)))
where coun > 30
and lag_coun1 > 30
and lag_coun2 > 30
and lag_coun3 > 30
and lag_coun4 > 30
and lag_coun5 > 30
and lag_coun6 > 30
TA贡献1796条经验 获得超4个赞
只需要把oracle 中turnc 函数 换成SQL Server的函数就可以!
trunc(add_time, day) --CONVERT(varchar(100),add_time, 23)
- 2 回答
- 0 关注
- 173 浏览
添加回答
举报