[英]Bigquery/ SQL: sequence in same group
I have a question in regards to finding the sequence between 2 page types using sql:我有一个关于使用 sql 查找两种页面类型之间的序列的问题:
Sample data we have:我们拥有的样本数据:
SessionID![]() |
Page Type![]() |
---|---|
123 ![]() |
account![]() |
123 ![]() |
raw![]() |
123 ![]() |
plp ![]() |
123 ![]() |
pdp ![]() |
123 ![]() |
account![]() |
123 ![]() |
plp ![]() |
123 ![]() |
sample![]() |
123 ![]() |
pdp ![]() |
123 ![]() |
plp ![]() |
123 ![]() |
pdp ![]() |
123 ![]() |
raw![]() |
Ideally output will look like below, only to include records when pdp is clicked right after plp理想情况下,output 如下所示,仅包含在 plp 之后单击 pdp 时的记录
SessionID![]() |
Page Type![]() |
---|---|
123 ![]() |
plp ![]() |
123 ![]() |
pdp ![]() |
123 ![]() |
plp ![]() |
123 ![]() |
pdp ![]() |
In order to operate based on order - you must have something to order on为了根据订单进行操作 - 你必须有一些东西要订购
Usually it is timestamp column or position or something else通常是时间戳列或 position 或其他
I assume you have one (in my sample I will use ts column as such)我假设你有一个(在我的示例中,我将使用 ts 列)
Consider below approach to get what you want考虑下面的方法来获得你想要的
select * from your_table
qualify (lag(page_type) over win = 'plp' and page_type = 'pdp')
or (lead(page_type) over win = 'pdp' and page_type = 'plp')
window win as (partition by sessionId order by ts)
with output与 output
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.