How to order by count desc in each group in a hive?

后端 未结 3 1594
暗喜
暗喜 2021-02-19 23:46

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:



        
相关标签:
3条回答
  • 2021-02-20 00:04
    select A, B, count(*) as cnt 
    from test_table 
    group by A, B 
    order by A, cnt desc;
    
    0 讨论(0)
  • 2021-02-20 00:12
    select A, B, count(*) as cnt from test_table group by A, B order by A asc, B asc, cnt desc;
    
    0 讨论(0)
  • 2021-02-20 00:14

    Try this query:

    If you want only order of A then:

    select A, B, count(*) as cnt from test_table group by A, B order by A asc;
    

    If you want order of A and B then:

    select A, B, count(*) as cnt from test_table group by A, B order by A asc,B asc;
    

    Hope this helps.

    0 讨论(0)
提交回复
热议问题