内部表SQL:
select a.型号,IIF(b.数量 is null,0,b.数量) +IIF(d.数量 is null,0 ,d.数量) as 出库,IIF(f.数量 is null,0 ,f.数量) as 入库 from ((({kc} as a
left join (select 型号,sum(数量) as 数量 from {表A} group by 型号) as b on a.型号=b.型号)
left join (select c.型号,sum(c.数量) as 数量 from (select 型号,数量 from {jh} where 状态='出库' or 状态='暂借') as c group by c.型号) as d on a.型号=d.型号 )
left join (select e.型号,sum(e.数量) as 数量 from (select 型号,数量 from {jh} where 状态='入库' or 状态='归还') as e group by e.型号) as f on a.型号=f.型号)
外部表SQL:
select a.型号,isnull(b.数量,0) +isnull(d.数量,0) as 出库,isnull(f.数量,0) as 入库 from kc as a
left join (select 型号,sum(数量) as 数量 from 表A group by 型号) as b on a.型号=b.型号
left join (select c.型号,sum(c.数量) as 数量 from (select 型号,数量 from jh where 状态='出库' or 状态='暂借') as c group by c.型号) as d on a.型号=d.型号
left join (select e.型号,sum(e.数量) as 数量 from (select 型号,数量 from jh where 状态='入库' or 状态='归还') as e group by e.型号) as f on a.型号=f.型号
[此贴子已经被作者于2009-10-23 23:55:21编辑过]