开发者

How to get number of occurance and the field value from a table

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜