应用滞后函数,直到在红移中条款
以下表(RedShift)
事件 | URL | 等级 | 标志 |
---|---|---|---|
Clic | url1 | 1 | |
查看 | URL2 | 2 | |
查看 | URL3 | 3✓clic | 。 |
url4 | 有 | 1 | |
查看 | url5 | 2✓ | 我 |
我想添加带有最后一个clic的url列 我尝试使用lag()函数,但我不知道偏移。是否有一种方法可以应用滞后直到上一个clic?
事件 | URL | 等级 | 旗帜 | 案例 |
---|---|---|---|---|
CLIC | URL1 | 1 | ||
查看 | URL2 | 2 | ||
查看 | URL33✓URL1 | | CLIC | URL4 |
| URL52✓url4 | 1 | ||
查看 | | | | |
SELECT *,
CASE
WHEN flag
AND event = 'view'
AND LAG(event) OVER (ORDER BY rank) = 'clic'
THEN LAG(url)
END
FROM myTable;
I have the below table (Redshift)
event | url | rank | flag |
---|---|---|---|
clic | url1 | 1 | |
view | url2 | 2 | |
view | url3 | 3 | ✓ |
clic | url4 | 1 | |
view | url5 | 2 | ✓ |
I would like to add a column with the url of the last clic. I tried with LAG() function but I don't know the offset. Is there a way to apply LAG until the previous clic ?
event | url | rank | flag | CASE |
---|---|---|---|---|
clic | url1 | 1 | ||
view | url2 | 2 | ||
view | url3 | 3 | ✓ | url1 |
clic | url4 | 1 | ||
view | url5 | 2 | ✓ | url4 |
SELECT *,
CASE
WHEN flag
AND event = 'view'
AND LAG(event) OVER (ORDER BY rank) = 'clic'
THEN LAG(url)
END
FROM myTable;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就像一个差距和岛问题一样,您想在每个景观岛的尽头显示最后一个差距(单击)的URL。
我们可以使用点击的累积计数来定义从单击开始的组,然后恢复每个组中唯一单击的URL:
请注意,这需要一列来对整个表上的行进行排序 - 我称之为
> id
。This reads like a gaps-and-islands problem, where you want to show the url of the last gap (a click) at the end of each island of views.
We can use the cumulative count of clicks to define groups that start with a click, and then recover the url of the unique click in each group :
Note that this requires a column to sort rows on the whole table - which I called
id
.