如:一表有20000条数据,销售数量>0 or 库存数量>0的有10000条,我要计算销售数量>0 or 库存数量>0中销售数量=0的有多少条,一般查询是这样
select count(*) from aa where 销售数量=0 and id in(select id from aa where 销售数量>0 or 库存数量>0
但我现在如何在字段中去体现出来?也就是不加后面的where条件,直接在from前能计算出来呢?

解决方案 »

  1.   

    select count(*) from aa where 销售数量=0 and 库存数量>0
      

  2.   

    select sum(case when 销售数量=0 and 库存数量>0 then 1 else 0 end) from aa
      

  3.   

    创建一个view,查询该view,哈哈。
      

  4.   

    你这个本来就有很多限制条件
    为什么你不用where来进行过滤了?
      

  5.   

    select sum(decode(sign(0-銷售數量),-1,1,0)) from aa
    union
    select sum(decode(sign(0-庫存數量),-1,1,0)) from aa;
      

  6.   

    select sum(decode(sign(0 - 库存数量), -1, decode(销售數量, 0, 1, 0), 0)) from aa