查找给定事件后发生的第一个事件
我正在使用一张表,该表由许多网络会话组成,其中包括各种事件和事件ID:s。为了简化我的问题,假设我有4列是session_id,event_name和event_id,其中事件ID可用于按上升/降序订购事件。我们还假装我们有很多事件,我对event_name的3个事件特别感兴趣:开放,提交和拒绝。假设这三个事件可以按任何顺序发生。
我想做的是,我想添加一个新的专栏,每个会话都说这两个事件“提交”和“衰落”中的两个事件首先是在事件“ Open”之后。我尝试使用First_value分区功能,但尚未成功使用。
因此,对于活动序列的会话:“ open”,...(中间发生的许多不同事件),“提交”,“衰落”,我想返回“提交”, 对于事件序列的会话:开放,... 对于“开放”之后的“提交”和“下降”的事件都没有发生的会议,我想退还null。
我希望这个问题及其公式很清楚。非常感谢您!
真挚地, 贝尔坦
I am working with a table consisting of a number of web sessions with various events and event id:s. To simplify my question, let's say that I have 4 columns which are session_id, event_name and event_id, where the event id can be used to order the events in ascending/descending order. Let's also pretend that we have a large number of events and that I am particularly interest in 3 of the events with event_name: open, submit and decline. Assume that these 3 events can occur in any order.
What I would like to do, is that I would like to add a new column that for each session says which, if any, of the two events 'submit' and 'decline' that first follows the event 'open'. I have tried using the FIRST_VALUE partition function but have not made it successfully work yet.
So for a session with event sequence: 'open', ... (a number of different events happening in between), 'submit', 'decline', I would like to return 'submit',
and for a session with event sequence: open, ... (a number of different events happening in between), 'decline', I would like to return 'decline',
and for a sessions for which none of the events 'submit' nor 'decline' happens after 'open', I would like to return null.
You can use the following table with name 'events' for writing example SQL code:
I hope the question and its formulation is clear. Thank you very much in advance!
Sincerely,
Bertan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在下面使用(假设您每次会话只接受或下降!)
,如果适用于问题中的示例数据 - 输出为
Use below (assuming you have only one accept or decline per session!)
if apply to sample data in your question - output is