sort within category and limit 5 for this hive table

后端 未结 1 2021
既然无缘
既然无缘 2021-01-29 04:42

I have a hive table A that has the following column

USER   ITEM    SCORE
U1      I1       S1
U1      I2       S2
...................

What I wan

相关标签:
1条回答
  • 2021-01-29 05:06

    should be something like this :

    select USER,collect_set(ITEM) from (
        select USER, ITEM,row_number () over (partition by USER order by SCORE desc) RN 
        from A
    ) t1
    where RN <= 5
    group by USER;
    
    0 讨论(0)
提交回复
热议问题