如何从下表中获取具有车辆数量的类别列表(按车辆编号的降序排列)。
车辆|类ab A
cd A
ef A
gh B
ij B
kl C
预期产出:
A 3
B 2
C 1
请帮帮我......
答案 0 :(得分:3)
您可以将聚合函数count()
与GROUP BY一起使用:
select category, count(*) Total
from yourtable
group by category
order by total desc;
请参阅Demo
答案 1 :(得分:0)
只需GROUP BY
,然后检索计数。也就是说,
SELECT COUNT(*) AS repetitions FROM Vehicles GROUP BY category