日期:2014-05-19 浏览次数:20918 次
select osi.plancode,
osi.gctcode,
(select sum(osi1.productnumber)
from chukudantable osi1
where osi.plantype = 2
and osi.isAgree != 0 osi1.plancode = osi.plancode),
(select sum(osi1.tounumber)
from chukudantable osi1
where osi.plantype = 2
and osi.isAgree != 0 osi1.plancode = osi.plancode)
from chukudantable osi
where osi.plantype = 2
and osi.isAgree = -1
and osi.inuse = 0
group by osi.plancode
------解决方案--------------------
for example
select osi.plancode,
osi.gctcode,
sum(case isAgree when 0 else osi.productnumber end),
sum(case isAgree when 0 else osi1.tounumber end)
from chukudantable osi
where osi.plantype = 2
and osi.inuse = 0
and not exists (select 1 from chukudantable
where plancode = osi.plancode
and isAgree = 0) --存在isAgree为0的不显示,也就是不选取
group by osi.plancode