Mysql计数按组发生

Sar*_*voo 5 mysql sql select

嗨我有关于mysql DB的下表.

?????????????????????????????????????????????????
? REVIEW_ID ? USER_ID ? STATUS ?   DATE_ADDED   ?
?????????????????????????????????????????????????
?       218 ?       2 ? cool   ? 20130121134811 ?
?       218 ?       2 ? cool   ? 20130121134812 ?
?       218 ?       2 ? lame   ? 20130121134813 ?
?       218 ?       2 ? funny  ? 20130121134814 ?
?       218 ?       2 ? funny  ? 20130121134815 ?
?       218 ?       2 ? funny  ? 20130121134816 ?
?       218 ?       2 ? lame   ? 20130121134817 ?
?????????????????????????????????????????????????
Run Code Online (Sandbox Code Playgroud)

我怎么能得到一个结果,当我根据user_id我需要得到每种类型的总状态的结果进行查询时:

???????????????????????
? STATUS ? TOTALCOUNT ?
???????????????????????
? cool   ?          2 ?
? funny  ?          3 ?
? lame   ?          2 ?
???????????????????????
Run Code Online (Sandbox Code Playgroud)

谢谢

Joh*_*Woo 13

使用COUNT()哪个是聚合函数,并根据它们进行分组status

SELECT  status, COUNT(*) totalCount
FROM    tableName
GROUP   BY status
Run Code Online (Sandbox Code Playgroud)

其他)