会话的SQL汇总

问题描述 投票:0回答:2

我有一个印象事件表,它有一堆时间戳和标记的开始/结束边界。我正在尝试将其推广到指标“此会话包含至少1次展示功能x”。我不确定如何做到这一点。任何帮助,将不胜感激。谢谢。

enter image description here

我想把它推到看起来像这样的东西:

account, session_start, session_end, interacted_with_feature
3004514, 2018-02-23 13:43:35.475, 2018-02-23 13:43:47.377, FALSE

我很容易说这个会话是否与该功能有任何交互。

sql amazon-redshift
2个回答
1
投票

也许聚合做你想要的:

select account, min(timestamp), max(timestamp), max(interacted_with_feature)
from t
group by account;

0
投票

我能够通过条件累积和来解决这个问题,以便为每一行生成会话组ID。

with cte as (
    select *
        , sum(case when session_boundary = 'start' then 1 else 0 end) 
              over (partition by account order by timestamp rows unbounded preceding)
          as session_num
    from raw_sessions
)

select account
    , session_num
    , min(timestamp) as session_start
    , max(timestamp) as session_end
    , bool_or(interacted_with_feature) as interacted_with_feature
from cte
group by account, session_num
© www.soinside.com 2019 - 2024. All rights reserved.