【问题标题】:How search row num partition by user如何按用户搜索行号分区
【发布时间】:2019-07-16 12:19:53
【问题描述】:

presto怎么写sql? 这是我的sql:

    select
t.user_id,t.loguni_datetime,t.page_type,t.action_type,t.tab_name,
 row_number()   OVER (PARTITION BY t.user_id
                    ORDER BY log_time) AS rnk
from datamart_iptv_shyd_sh.f_visit_click_detail t 
where t."year"='2019' and t."month"='07' and t."day"='10'
and t.page_type is not null
order by t.user_id,log_time

我明白了:

但我想通过 userid 和 page_type 得到分区,如下所示:

rnk 客场以 '/epg/portal' 开头

谢谢~

【问题讨论】:

  • 您的查询引用了yearmonthday,但这些不在您的结果集中。你说按page_type 分区,但action_type 似乎更合适。这个问题很不清楚。
  • 不好意思,我的英文很差,想用userid分区,然后pagetype进行时间排序,遇到portl页面重新排序。结果像第二张图中的红字。

标签: sql presto


【解决方案1】:

在分区上添加 t.page_type 并使用dense_rank

select
t.user_id,t.loguni_datetime,t.page_type,t.action_type,t.tab_name,
 dense_rank()   OVER (PARTITION BY t.user_id,t.page_type
                    ORDER BY log_time) AS rnk
from datamart_iptv_shyd_sh.f_visit_click_detail t 
where t."year"='2019' and t."month"='07' and t."day"='10'
and t.page_type is not null
order by t.user_id,log_time

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-02
    • 1970-01-01
    • 2017-02-10
    • 1970-01-01
    • 2022-12-06
    • 1970-01-01
    • 2018-10-03
    相关资源
    最近更新 更多