开发者

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

开发者 https://www.devze.com 2023-04-01 03:33 出处:网络
Table ID Name 1abc 2cde 3xyz 4abc 5cde 6cde My expected result is abc 2 cde 3 how will be th开发者_JS百科e query ?You can do this with a GROUP BY statement:

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

精彩评论

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

关注公众号