这是HQL:
select A, B, count(*) as cnt from test_table group by A, B order by cnt desc;
示例输出如下:
a1 | b1 | 5
a2 | b1 | 3
a1 | b2 | 2
a2 | b2 | 1
但我想要的是在每组A中执行order by
,并且预期输出如下:
a1 | b1 | 5
a1 | b2 | 2
a2 | b1 | 3
a2 | b2 | 1
任何人都可以让我知道如何在一个 HQL中解决此问题?非常感谢!
答案 0 :(得分:21)
select A, B, count(*) as cnt
from test_table
group by A, B
order by A, cnt desc;
答案 1 :(得分:0)
尝试此查询:
如果您只想订购A,那么:
select A, B, count(*) as cnt from test_table group by A, B order by A asc;
如果您想订购A和B,那么:
select A, B, count(*) as cnt from test_table group by A, B order by A asc,B asc;
希望这有帮助。
答案 2 :(得分:0)
select A, B, count(*) as cnt from test_table group by A, B order by A asc, B asc, cnt desc;