使用一个MySQL语句计算所有案例

时间:2014-01-06 15:28:36

标签: mysql

我想返回总计数,然后还返回where语句的结果。

SELECT count(cases) 
from `table`
WHERE stats = 'open'.

以上将计算stats = open的位置,我需要首先计算所有情况,然后还要计算where语句。类似的东西:

SELECT count(cases)
from `table`
\\return count of all cases
where stats= count(open).

2 个答案:

答案 0 :(得分:2)

SELECT SUM( stats = 'open' ),  -- count of all stats open
       SUM( stats <> 'open' )  -- count of all stats NOT open
from `table`;

答案 1 :(得分:0)

尝试使用:

SELECT COUNT(cases)
FROM `table`
HAVING stats = COUNT(open)