读书人

SQL高手解决库存有关问题

发布时间: 2012-09-18 16:21:42 作者: rapoo

求助SQL高手解决库存问题
有表:
A:商品表 goods
B:仓库 lib(有A、B、C、D四个仓库)
C1: 进货单 C2:进货详细表
D1: 出货单 D2:出货详细表
E1: 退货单 E2:退货详细表
更换单
F1:更换入 F2:更换入详细表
G1:更换出 G2:更换出详细表
调拨单
H1:调拨入 H2:调拨入详细单
I1: 调拨出 I2:调拨出详细单
J1:退出单 J2:退出详细单
异动单
L1:库存增加单 L2:库存增加详细单
M1:库存减少单 M2:库存减少详细单

查询所有商品在各个仓库的库存数量

[解决办法]
这个可以这样

SQL code
select d.code,d.num*(-1) as 'SZ',null as 'HK',null as 'SS',null as 'SH' from 出货详细单 as D,出货单 as t  where t.orderno=d.orderno and t.outlib='A' and t.nouse=''union allselect d.code,null as 'SZ',d.num*(-1) as 'HK',null as 'SS',null as 'SH' from 出货详细单 as D,出货单 as t  where t.orderno=d.orderno and t.outlib='B' and t.nouse=''union allselect d.code,null as 'SZ',null as 'HK',d.num*(-1) as 'SS',null as 'SH' from 出货详细单 as D,出货单 as t  where t.orderno=d.orderno and t.outlib='C' and t.nouse=''union allselect d.code,null as 'SZ',null as 'HK',null as 'SS',d.num*(-1) as 'SH' from 出货详细单 as D,出货单 as t  where t.orderno=d.orderno and t.outlib='D' and t.nouse='' 

读书人网 >SQL Server

热点推荐