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 货号
解决方案 »
- SQL2005的存储过程是要怎么添加啊
- 求助:SqlServer2005的tcp/ip协议里面的默认配置什么呢?
- 已知点的经纬度,怎样在转化成屏幕上的xy坐标?并在电脑屏幕上表示出来?
- SQLServer惊天大BUG? [code=SQL] select * from table_name where col_date<='2010-6-28
- sql树形显示
- 一些比较菜的问题
- 怎么写?怎样将一个表中的所有记录输出到文本文件,Word,Excel文档中?
- 请问如何通过SQL得到一个表的记录的最后新增或修改,删除时间?
- 存储过程中的参数类型转换问题,在线等。
- 存储过程出错。帮忙看看。急!!!!
- 如何用一个表中的记录动态建立一个SQL表
- 如何取得vabinary类型的数据的长度
入库数量 = 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
from table1 inner join table2 on table1.货号=table2.货号 ),出库数量
from (select 出库数量 from table3 where 货号 = table2.货号 and table1.货号)
exiset ())
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