用户如何搜索行编号分区

时间:2019-07-15 09:47:32

标签: sql presto

如何在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

我明白了:

enter image description here

但是我想按用户名和page_type进行分区,如下所示: enter image description here

rnk距离以'/ epg / portal'

开头

谢谢〜

1 个答案:

答案 0 :(得分:0)

在分区上添加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