表
ID Name
1 abc
2 cde
3 xyz
4 abc
5 cde
6 cde
我的预期结果是
abc 2
cde 3
查询怎么样?
答案 0 :(得分:6)
您可以使用GROUP BY
声明执行此操作:
SELECT name, count(*) cnt
FROM your_table
GROUP BY name;
根据@ jadarnel27的建议,您可以将结果限制为仅显示重复项,如下所示:
SELECT name, count(*) cnt
FROM your_table
GROUP BY name
HAVING cnt > 1;
答案 1 :(得分:2)
试试这个:
SELECT Name, count(*)
FROM Table
GROUP BY Name
ORDER BY Name