2017-04-08 18 views
-1
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 
+0

你從哪裏得到這個區間函數的規範?另外,你已經標記了MS SQL Server以及google bigquery。你正在使用哪些? – Ash

+0

我正在使用這兩個。但是,如果我通過任何一個是好的 – Pranav

+0

當你嘗試時會發生什麼?如果你還沒有嘗試過,你應該在發佈之前。如果你嘗試過,你應該告訴我們發生了什麼事。 –

回答

0

對於MSSQL服務器,你可以嘗試

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 
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) 
+0

非常感謝。這在SQL Server中起作用。謝謝喬爾。 Google Big查詢中是否有類似的內容?如果你請幫忙。 – Pranav

+0

只是想出了大查詢。一切工作正常!感謝大家的幫助。 – Pranav