开发者

MySQL: Count occurances of distinct values

I am trying to find a MySQL query that will find distinct values in a particular field, count the number of occurrences of that value.

example db

content_type    content_page    content_order
     23              25               1
     23              26               2
     24              25               2
     24              26               1
     24     开发者_如何学Python         28               1
     29              25               3

expected result

content_type    count
    23             2   
    24             3 
    29             1 

Thanks


Use the GROUP BY clause

SELECT content_type, COUNT(*)
FROM table_name
GROUP BY content_type

http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html


SELECT content_type, COUNT(content_type) as count
FROM mytable
GROUP BY content_type
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜