Hive如何在GROUP BY 后,获取每个GROUP的Top N

SELECT page-id, user-id, clicks  
FROM (  
    SELECT page-id, user-id, rank(page-id) as rank, clicks FROM (  
        SELECT page-id, user-id, clicks FROM mytable  
        DISTRIBUTE BY page-id  
        SORT BY page-id, clicks desc  
) a ) b  
WHERE rank < 5  
ORDER BY page-id, rank  
    原文作者:那只媛
    原文地址: https://www.jianshu.com/p/026fdf069190
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞