select
gysbh ,
gysname = (select gysname from a where a.gysbh = d.gysbh),
Cmoney = (select sum(dj*sl) from c where jhdh in (select jhdh from b where b.gysbh = d.gysbh and b.jhdh = c.jhdh )
- ytmoney
from d
gysbh ,
gysname = (select gysname from a where a.gysbh = d.gysbh),
Cmoney = (select sum(dj*sl) from c where jhdh in (select jhdh from b where b.gysbh = d.gysbh and b.jhdh = c.jhdh )
- ytmoney
from d
- ytmoney //这句执行有问题
from (
select b.gysbh,sum(c.sl*c.dj) as cmoney
from b,c
where b.jhdh=c.jhdh
) as t1,a,d
where a.gysbh=t1.gysbh
and a.gysbh=d.gysbhor (d表一个gysbh有多条记录的情况):select a.gysbh,a.gysname,t1.cmoney-t2.ytmoney as Cmoney
from (
select b.gysbh,sum(c.sl*c.dj) as cmoney
from b,c
where b.jhdh=c.jhdh
) as t1,a,
(
select gysbh,sum(ytmoney) as ytmoney
from d
) as t2
where a.gysbh=t1.gysbh
and a.gysbh=t2.gysbh
select gysb.gysbh,gysb.gysname,t1.cmoney-t2.ytmoney as cmoney
from (
select jhdb.gysbh,sum(jhmxb.sl*jhmxb.dj) as cmoney
from jhdb,jhmxb
where jhdb.jhdh=jhmxb.jhdh
GROUP BY jhdb.gysbh
)as t1,gysb,
(select gysbh,sum(ytmoney) as ytmoney
from thdb
GROUP BY gysbh
) as t2
where gysb.gysbh=t1.gysbh and gysb.gysbh=t2.gysbh