本帖最后由 wangjinwei6912 于 2011-07-25 14:21:31 编辑

解决方案 »

  1.   


    select count(1)-count(case when status = 1 then 1 else null end)
      from order
    ;
      

  2.   

    select count(1) - count(case
                              when status = '01' then
                               1
                              else
                               0
                            end)
      from order;
      

  3.   


    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
      

  4.   

    假如是 查询 总记录数和 status 为 ‘01’ 或者 ‘03’ 的记录数之差 呢。。
      

  5.   

    假如是 查询 总记录数和 status 为 ‘01’ 且 name 是 ‘aaa’,的记录数之差 呢。。
      

  6.   

    select count(1)-sum(decode(status ,'01',1,0)) from t
      

  7.   

    假如是 查询 总记录数和 status 为 ‘01’ 且 name 是 ‘aaa’,的记录数之差 呢。。
      

  8.   


    --查询 总记录数和 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;
      

  9.   

    这样不就行了吗?--------总记录数和 status 为 ‘01’的记录数之差
    select
    from order 
    where nvl(status,0)<>'01'
      

  10.   

    楼主想要的是下面的结果吧:with tab 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 DISTINCT tab.status, COUNT(0) OVER() - COUNT(0) OVER(PARTITION BY status) FROM tab---------------------------
    status  记录数之差 
    01 1
    02 2