我有一个基本的表
id | type | date
---------------------------------------
1 | photo | 2015-11-20
2 | video | 2015-02-1
3 | file | 2016-01-17
4 | photo | 2016-01-23
5 | photo | 2016-01-27
6 | video | 2016-01-27
我的基本查询是:
SELECT COUNT(type) FROM fields GROUP BY type;
导致:
count
-----
3
2
1
哪个接近,但我如何将类型与数字相关联?理想情况下,我想要接近这个:
count | type
------------
3 | photo
2 | video
1 | file
答案 0 :(得分:1)
只需按计数(*)
更改计数(类型) SELECT COUNT(*), type FROM fields GROUP BY type