create view 视图名
as
select 货号,入库数量=sum(入库数量),出库数量=sum(出库数量)
from(
select 货号,入库数量,出库数量=0 from 入库表1
union all
select 货号,入库数量,出库数量=0 from 入库表2
union all
select 货号,入库数量=0,出库数量 from 出库表
)a group by 货号

解决方案 »

  1.   

    select 货号,
           入库数量 = isnull((select sum(入库数量) from 入库表1 where 入库表1.货号 = a.货号),0) +
    isnull((select sum(入库数量) from 入库表2 where 入库表2.货号 = a.货号),0),
           出库数量 = isnull((select sum(出库数量) from 出库表 where 出库表.货号 = a.货号),0)
    from 
    (select 货号 from 入库表1
     union
     select 货号 from 入库表2
     union
     select 货号 from 出库表
    ) a
      

  2.   

    select 货号, 入库数量(select sum(table1.入库数量)+sum(table2.入库数量)
     from table1 inner join table2 on table1.货号=table2.货号 ),出库数量 
    from (select 出库数量 from table3 where 货号 = table2.货号 and table1.货号)
    exiset ())
      

  3.   

    改正:
    select 货号,sum(入库数量) as a,(出库数量) as b from
    (select sum(table1.z入库数量)+sum(table2.入库数量) from table1.inner join 
    table2.入库数量 on table1.货号=table2.货号) as a
    cross join 
    (select 出库数量 from table3 where table3.货号=table1.货号 and table2.货号 )
    as b 
    order by 货号 asc