查询每种产品上月末的库存,和下月初到现在的入库数,出库树,及在库数,怎样在一张表体现.我只实现了后三个,第一个不知道怎么弄,代码如下
select c.b,d.a,c.p_code,c.c_name ,c.p_all_name,c.p_all_tufan,c.p_all_pinfan,
zw.zw_now ,zw.zw_time ,zw.unit_price,zw.total_money
from cpk.dbo.zw_now zw,
(select ISNULL(SUM( cpk.dbo.ZHUWEN_TABLE.zhuwen_number),0) as b ,cpk.dbo.p_all_table.id as p_code,
cpk.dbo.p_all_table.p_all_name as p_all_name ,cpk.dbo.p_all_table.p_all_tufan as p_all_tufan,
cpk.dbo.p_all_table.p_all_pinfan as p_all_pinfan,cpk.dbo.custums.c_name as c_name,
cpk.dbo.custums.c_code as c_code
from cpk.dbo.ZHUWEN_TABLE,cpk.dbo.p_all_table,cpk.dbo.custums
where cpk.dbo.ZHUWEN_TABLE.delivery_time between '2007-10-1' and '2007-12-30'
and cpk.dbo.ZHUWEN_TABLE.p_code=cpk.dbo.p_all_table.id and cpk.dbo.ZHUWEN_TABLE.c_code=cpk.dbo.custums.c_code
group by cpk.dbo.p_all_table.id ,cpk.dbo.p_all_table.p_all_name,cpk.dbo.p_all_table.p_all_tufan,
cpk.dbo.p_all_table.p_all_pinfan,
cpk.dbo.custums.c_name,cpk.dbo.custums.c_code) c
full join
(select ISNULL(SUM( cpk.dbo.sell.sell_number),0) as a,cpk.dbo.p_all_table.id as p_code,cpk.dbo.custums.c_code as c_code
from cpk.dbo.sell,cpk.dbo.p_all_table,cpk.dbo.custums
where cpk.dbo.sell.sell_date between '2007-10-1' and '2007-12-30' and
cpk.dbo.sell.p_code=cpk.dbo.p_all_table.id and cpk.dbo.sell.c_code=cpk.dbo.custums.c_code
group by cpk.dbo.p_all_table.id,cpk.dbo.custums.c_code) d
on c.p_code=d.p_code and c.c_code=d.c_code
where c.p_code=zw.p_code and c.c_code=zw.c_code
order by c.p_code DESC
------解决方案--------------------
把上月末的库存做个子查询,然后与后三个连接查询就行了