Table
ID Name
1 abc
2 cde
3 xyz
4 abc
5 cde
6 cde
My expected result is
abc 2
cde 3
how will be th开发者_JS百科e query ?
You can do this with a GROUP BY
statement:
SELECT name, count(*) cnt
FROM your_table
GROUP BY name;
As suggested by @jadarnel27, you can limit the results to only showing duplicates as follows:
SELECT name, count(*) cnt
FROM your_table
GROUP BY name
HAVING cnt > 1;
Try this:
SELECT Name, count(*)
FROM Table
GROUP BY Name
ORDER BY Name
精彩评论