日期:2014-05-17 浏览次数:20926 次
select count(1)-count(case when status = 1 then 1 else null end) from order ;
------解决方案--------------------
select count(1) - count(case
when status = '01' then
1
else
0
end)
from order;
------解决方案--------------------
with t as ( select '01' id,'aaa' name,'01' status from dual union all select '02' id,'aba' name,'02' status from dual union all select '01' id,'aaa' name,'01' status from dual ) select tab1.a - tab2.b from (select count(1) a from t) tab1, (select count(1) b from t where t.status = '01') tab2
------解决方案--------------------
--查询 总记录数和 status 为 ‘01’ 且 name 是 ‘aaa’,的记录数之差 select count(1)-sum(case when status = '01' and name = 'aaa' then 1 else 0 end) from order; -- 查询 总记录数和 status 为 ‘01’ 或者 ‘03’ 的记录数之差 select count(1)-sum(case when status in ('01','03') then 1 else 0 end) from order;