我的MySql db表结构是:
id | status
1 | Open
2 | Open
3 | Closed
4 | Open
5 | Closed
我希望计算打开和关闭行的总数。
Status | Total
Open | 3
Closed | 2
我用过
SELECT count(distinct status) as Total FROM my_tbl
但它返回
Total
2
答案 0 :(得分:6)
SELECT status,
COUNT(id) AS `total`
FROM your_table
GROUP BY status
ORDER BY total DESC