您可以将滞后函数的结果转换为时间戳。我基本上想要在几秒钟内获得两个时间戳的差异。 使用以下代码,系统告诉我'last_timestamp'的类型未知。当我将鼠标光标放在内部查询的列'last_timestamp'上时,我可以看到它的类型为timestamp。
SELECT clientId, timestamp
FROM (
SELECT clientId, timestamp,
LAG(timestamp,1) OVER
(PARTITION BY clientId ORDER BY timestamp)
AS last_timestamp
FROM [oxidation.201602]
) last
WHERE (TIMESTAMP_TO_SEC(timestamp) - TIMESTAMP_TO_SEC(last_timestamp) >= (60 * 30))
OR last_timestamp IS NULL
答案 0 :(得分:1)
SELECT clientId, timestamp
FROM (
SELECT clientId, timestamp, timestamp_sec,
LAG(timestamp_sec, 1)
OVER (PARTITION BY clientId ORDER BY timestamp_sec) AS prev_timestamp_sec
FROM (
SELECT clientId, timestamp, TIMESTAMP_TO_SEC(timestamp) as timestamp_sec
FROM [oxidation.201602]
)
) last
WHERE timestamp_sec - prev_timestamp_sec >= 60 * 30
OR prev_timestamp_sec IS NULL