我将用示例
解释我的问题create table foo(id int,idx int,idy int,fld int,fldx varchar);
insert into foo values (1,2,3,55,'AA'),(2,3,4,77,'AB'),(3,4,8,55,'AX'),(9,10,15,77,'AR'),
(3,4,8,11,'AX'),(3,4,8,65,'AX'),(3,4,8,77,'AX');
id,idx,idy, fld,fldx
1 2 3 55 AA
2 3 4 77 AB
3 4 8 55 AX
9 10 15 77 AR
3 4 8 11 AX
3 4 8 65 AX
3 4 8 77 AX
我需要按降序选择列fld
及其每个列的总计数(fld
预期结果:
fld count
---------
77 3
55 2
11 1
65 1
答案 0 :(得分:0)
select fld
,count(fld) rw_count
from foo
group by fld
order by rw_count desc
答案 1 :(得分:0)
select fld,count(*) from foo group by 1 order by 2 desc ;