hive topN 实现

hive的topN实现

hive的topN实现方式有很多种,网上有一些通过自己写的udf实现,下面将我写的sql模式贴一下

核心原理通过group by 分组求和 之后 用order by 进行全局排序 之后在limit n 取你想要的 topn 排名

上sql:
select obj , cnt from ( select obj ,count(obj) as cnt from action_raw where verb ='SHARE_ALBUM' and log_date >= '2012-01-01' and log_date <= '2012-12-12' group by obj ) tmp order by cnt desc limit 10

猜你喜欢

转载自wwangcg.iteye.com/blog/1747516