猿问

如下内容,请问该怎么转换成sql server语句?

oracle语句
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

谁能帮我转换成sql server语句

慕桂英4014372
浏览 174回答 2
2回答

吃鸡游戏

select IDfrom (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_coun6from (select ID, trunc(add_time, day) time, count(*) counfrom tablewhere time > 10and time < 24group by ID, trunc(add_time)))where coun > 30and lag_coun1 > 30and lag_coun2 > 30and lag_coun3 > 30and lag_coun4 > 30and lag_coun5 > 30and lag_coun6 > 30

慕的地8271018

只需要把oracle 中turnc 函数 换成SQL Server的函数就可以!trunc(add_time, day) --CONVERT(varchar(100),add_time, 23)
随时随地看视频慕课网APP

相关分类

Oracle
我要回答