2012-02-02 35 views
0

我的MySQL數據庫的表結構是:MySQL的:基於字段數行命名

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 

回答

6
 

SELECT status, 
COUNT(id) AS `total` 
FROM your_table 
GROUP BY status 
ORDER BY total DESC 
 
+0

感謝ü。謝謝你。謝謝你。 – 2012-02-02 08:24:17