如:一表有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前能计算出来呢?
select count(*) from aa where 销售数量=0 and id in(select id from aa where 销售数量>0 or 库存数量>0
但我现在如何在字段中去体现出来?也就是不加后面的where条件,直接在from前能计算出来呢?
为什么你不用where来进行过滤了?
union
select sum(decode(sign(0-庫存數量),-1,1,0)) from aa;