我想返回总计数,然后还返回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).
答案 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)