转载自:http://stackoverflow.com/questions/9390698/hive-getting-top-n-records-in-group-by-query
原标题:Hive getting top n records in group by query
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
qwrwrqw