开发者

Need a hand with a simple query

I need a help with a query. I think is not so difficult.

I need to do a select with distinct and at the same time, do a count(*) of how many rows are returned by this distinct.

One example:

Table names>
Id   Name
1    john
2    john
3    mary

I need a query thats return:

Name    Total
john    2
mary    开发者_如何学运维1


select name, count(*) from names group by name;


SELECT name, COUNT(*) FROM names GROUP BY name


SELECT name, count(*) as occurrences FROM names GROUP BY name
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜