select distinct c.仓库,c.商品编码,c.数量,e.数量,d.数量 from (select a.仓库,a.商品编码,(a.数量-b.数量) as 数量 from (select 仓库,商品编码,sum(数量) as 数量 from dbo.入库汇总 where 入库日期 <'2003-04-03' group by 仓库,商品编码) a, (select 仓库,商品编码,sum(数量) as 数量 from dbo.出库汇总 where 日期 <'2003-04-03' group by 仓库,商品编码) b where (a.仓库=b.仓库) and (a.商品编码=b.商品编码) union --两个都相等时 select a.仓库,a.商品编码,sum(数量)from dbo.入库汇总 a where a.仓库 not in (select 仓库 from dbo.出库汇总) and 入库日期 <'2003-04-03' group by a.仓库,a.商品编码) c, --a的仓库不在b的仓库中 ---&&&&&算出余额数量
select distinct c.仓库,c.商品编码,c.数量,e.数量,d.数量 from (select a.仓库,a.商品编码,(a.数量-b.数量) as 数量 from //YYYYYYYYYY,此处select的字段数目必须与第一个相同 ................................................下同. (select 仓库,商品编码,sum(数量) as 数量 from dbo.入库汇总 where 入库日期 <'2003-04-03' group by 仓库,商品编码) a, (select 仓库,商品编码,sum(数量) as 数量 from dbo.出库汇总 where 日期 <'2003-04-03' group by 仓库,商品编码) b where (a.仓库=b.仓库) and (a.商品编码=b.商品编码) union --两个都相等时 select a.仓库,a.商品编码,sum(数量)from dbo.入库汇总 a where a.仓库 not in (select 仓库 from dbo.出库汇总) and 入库日期 <'2003-04-03' group by a.仓库,a.商品编码) c, --a的仓库不在b的仓库中 ---&&&&&算出余额数量最好搞个外连接 left join on
(select a.仓库,a.商品编码,(a.数量-b.数量) as 数量 from
(select 仓库,商品编码,sum(数量) as 数量 from dbo.入库汇总
where 入库日期 <'2003-04-03'
group by 仓库,商品编码) a,
(select 仓库,商品编码,sum(数量) as 数量 from dbo.出库汇总
where 日期 <'2003-04-03'
group by 仓库,商品编码) b
where (a.仓库=b.仓库) and (a.商品编码=b.商品编码) union --两个都相等时
select a.仓库,a.商品编码,sum(数量)from dbo.入库汇总 a
where a.仓库 not in (select 仓库 from dbo.出库汇总)
and 入库日期 <'2003-04-03'
group by a.仓库,a.商品编码) c, --a的仓库不在b的仓库中
---&&&&&算出余额数量
(select a.仓库,a.商品编码,(a.数量-b.数量) as 数量 from //YYYYYYYYYY,此处select的字段数目必须与第一个相同 ................................................下同.
(select 仓库,商品编码,sum(数量) as 数量 from dbo.入库汇总
where 入库日期 <'2003-04-03'
group by 仓库,商品编码) a,
(select 仓库,商品编码,sum(数量) as 数量 from dbo.出库汇总
where 日期 <'2003-04-03'
group by 仓库,商品编码) b
where (a.仓库=b.仓库) and (a.商品编码=b.商品编码) union --两个都相等时
select a.仓库,a.商品编码,sum(数量)from dbo.入库汇总 a
where a.仓库 not in (select 仓库 from dbo.出库汇总)
and 入库日期 <'2003-04-03'
group by a.仓库,a.商品编码) c, --a的仓库不在b的仓库中
---&&&&&算出余额数量最好搞个外连接 left join on