如何通过计数desc在蜂巢中的每个组中进行排序? [英] How to order by count desc in each group in a hive?
本文介绍了如何通过计数desc在蜂巢中的每个组中进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
选择A,B,count(*)as cnt from test_table group by A,B order通过cnt desc;
示例输出如下:
a1 | b1 | 5
a2 | b1 | 3
a1 | b2 | 2
a2 | b2 | 1
但我想要的是按顺序执行 $ c>在每个A组中,并且预期的输出如下所示:
a1 | b1 | 5
a1 | b2 | 2
a2 | b1 | 3
a2 | b2 | 1
任何人都可以给我一些想法如何解决这个问题,只需一个 HQL?非常感谢!
解决方案
选择A,B,count(*)as cnt
from test_table
group by A,B
order by A,cnt desc;
Here's the HQL:
select A, B, count(*) as cnt from test_table group by A, B order by cnt desc;
The sample output is as follows:
a1 | b1 | 5
a2 | b1 | 3
a1 | b2 | 2
a2 | b2 | 1
But what I want is to do the order by
in each group of A, and the intended output is like:
a1 | b1 | 5
a1 | b2 | 2
a2 | b1 | 3
a2 | b2 | 1
Could anyone can give me some idea how to resolve this problem in just one HQL? Thanks a lot!
解决方案
select A, B, count(*) as cnt
from test_table
group by A, B
order by A, cnt desc;
这篇关于如何通过计数desc在蜂巢中的每个组中进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文