特定行之间的差异

difference between specific rows

我想估计用户在外部设备上停留的时间 link。因此,我想了解他们点击外部 link 和他们下次点击我的网站时的区别。

我的数据库如下所示(列出了重要的列):

到目前为止,我已经确定了所有超过 1 个 clsfd_event_action 的会话。但是,我很难过滤出会话必须有外部 link 点击,加上其他 clsfd_event_action(s).

select clsfd_session_id, count(*)
from table
group by 1
having clsfd_session_id> 1

我想要的是所有具有外部 link 单击 (= R2SExternalBegin) 的会话,然后是另一行(这样会话不会结束,但访问者 returns网站)。

在下图中,您可以看到 1 个会话,包括 1 个外部 link 单击 (R2SExternalBegin),然后是 1/更多行(因此会话不会在外部 link 点击结束) =49=])。红色矩形中最后一列数字之间的差异是在外部花费的时间 link。

我想要的输出: 所有具有 1/多个 R2SExternalBegin clsfd_event_action 的会话,后面跟着另一行(这意味着用户返回该站点)。请注意,大约有 50 种不同的 clsfd_event_action。

select clsfd_session_id, count(*)
from table
group by 1
having
   -- there was a 'R2SExternalBegin'
   min(case when clsfd_event_action  = 'R2SExternalBegin' then hit_start_time_num end)
   -- and there was different action later
 < max(case when clsfd_event_action <> 'R2SExternalBegin' then hit_start_time_num end)