间隔功能有问题。我用它的方式?

时间:2017-04-08 03:10:57

标签: sql-server

select top 10 * 
from James.activity_gc a 
left join James.activity_gc as James.activity_gc1 b 
on a.user_id = b.user_id
and a.time = b.time - interval '1' day

2 个答案:

答案 0 :(得分:1)

问题标记为sql-server,但Sql Server不使用Interval关键字。相反,你这样做:

select top 10 * 
from James.activity_gc a 
left join James.activity_gc as James.activity_gc1 b 
    on a.user_id = b.user_id
    and a.time = DATEADD(day, -1, b.time)

答案 1 :(得分:0)

对于MSSQL Server,您可以尝试

select top 10 * 
from James.activity_gc a 
left join James.activity_gc as James.activity_gc1 b 
on a.user_id = b.user_id
and DATEDIFF(day, a.time, b.time) = 1