如何在MYSQL中使用COUNT和DISTINCT为每个不同的值创建单独的计数?

时间:2015-07-21 19:31:29

标签: mysql count distinct

我在MYSQL中有一个城市和县的列表,每个城市和县都代表一个独特的数据点。我想运行一个查询,计算每个不同县出现的次数。例如:

city            state       county
chantilly       virginia     fairfax
chantilly       virginia     fairfax
reston          virginia     fairfax
leesburg        virginia     loudon
ashburn         virginia     loudon
manassas        virginia     prince william 

应该导致:

county        count
fairfax          3
loudon           2
prince william   1

1 个答案:

答案 0 :(得分:0)

select county, count(county) as Count from table group by county;