英文:
lag of app_remove giving null result set
问题
你好,以下是您的翻译:
我正在尝试找出每个用户在移除应用之前的最后3个事件。
以下是我目前的代码:
select
lag(event_name,3) over(partition by user_pseudo_id order by event_timestamp) as lag_event_name_3,
lag(event_name,2) over(partition by user_pseudo_id order by event_timestamp) as lag_event_name_2,
lag(event_name) over(partition by user_pseudo_id order by event_timestamp) as lag_event_name
from table_name
where event_name = 'app_remove'
and user_pseudo_id in (select * from dataset)
问题在于我得到了一个空的结果集。我是否漏掉了什么?谢谢。
英文:
I am trying to figure out the last 3 events before app removal for each user.
Here is my code so far:
select
lag(event_name,3) over(partition by user_pseudo_id order by event_timestamp) as lag_event_name_3,
lag(event_name,2) over(partition by user_pseudo_id order by event_timestamp) as lag_event_name_2,
lag(event_name) over(partition by user_pseudo_id order by event_timestamp) as lag_event_name
from table_name
where event_name = 'app_remove'
and user_pseudo_id in (select * from dataset)
The problem is that I am getting a null result set. Am I missing something here? Thanks
答案1
得分: 0
将此建议作为@nbk的答案添加,以供社区查看。
在选择子句中添加另一个字段,以填充由于分区记录而导致的空值。
选择事件名称,lag(event_name,3)...
窗口函数的良好参考资料在这里:https://cloud.google.com/bigquery/docs/reference/standard-sql/window-function-calls#def_window_spec
英文:
Adding this suggestion as answer by @nbk for the visibility of the community.
Adding another field in the select clause to fill the null values due to partitioned records.
>SELECT event_name, lag(event_name,3)...
A good reference for window functions here: https://cloud.google.com/bigquery/docs/reference/standard-sql/window-function-calls#def_window_spec
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论