我不断收到错误:
语法错误:在“,”或附近行:4 位置:3
在尝试为来自 Amazon Redshift 的会话创建跟踪时在 Periscope 上。当我尝试仅查询 id、时间戳和 LAG 操作时,LAG 操作似乎会引发错误。
SELECT
id
, timestamp
, SUM(is_new_session) OVER (ORDER BY id, timestamp) AS global_session_id
, SUM(is_new_session) OVER (PARTITION BY id ORDER BY timestamp) AS user_session_id
FROM (SELECT -- creates session
id
, timestamp
, CASE
WHEN EXTRACT('EPOCH' FROM timestamp) - EXTRACT('EPOCH'
FROM last_event) >= (60 * 10) OR last_event IS NULL THEN 1
ELSE 0
END AS is_new_session
FROM (SELECT
id
, timestamp
, LAG(timestamp,1) OVER (PARTITION BY id ORDER BY timestamp) AS last_event
FROM ios.tracks) last
) final