只是个一般性的问题。您能在RDBMS中讨论日志吗?
例如,假设您只有三列( 1)时间戳2) URL 3) UserID可以根据传统关系数据库管理系统中的X分钟活动来讨论日志。输出可能看起来像四列,1)时间戳2) URL3) UserID 4)SessionID。
我想不是,而是想听听别人的意见。
谢谢
发布于 2015-03-02 22:35:55
这有点棘手,但可以使用嵌套的窗口聚合函数来完成,如
SELECT timestamp, UserID, URL,
SUM(newSession) -- cumulative sum over 0/1
OVER (PARTITION BY UserId
ORDER BY timestamp
ROWS UNBOUNDED PRECEDING) AS SessionID
FROM
(
SELECT
ts_col, UserID, URL,
-- calculate the timestamp difference between current and previous row
CASE WHEN timestamp - LAG(timestamp)
OVER (PARTITION BY UserId
ORDER BY timestamp) > INTERVAL 'X minutes'
THEN 1 -- new session starts
ELSE 0 -- part of the old session
END AS newSession
) AS dt有些DBMSes (例如Vertica & Aster)支持使用内置函数进行会话化,而在其他情况下,您可能会实现用户定义的函数。
https://stackoverflow.com/questions/28819867
复制相似问题