计算mysql中唯一数据的出现次数

时间:2014-04-17 17:51:40

标签: mysql count

所以我知道如果我想要计算具有相同城市名称的条目数,我将使用以下代码:

SELECT *, COUNT(*) AS count
FROM location
GROUP BY city
ORDER BY count
DESC

如果我想计算具有相同城市名称和州名的条目数量,我该如何去做呢?

citynameA,stateNameB =具有相同cityname和statename的条目数

1 个答案:

答案 0 :(得分:3)

您可以将多个字段与group by一起使用,例如

SELECT city, state, COUNT(*) AS count
FROM location
GROUP BY city, state
ORDER BY count
DESC