日期:2014-05-18  浏览次数:20391 次

求收发存汇总sql
表名:JSKLNA  
需要 :期初数量、 期初金额,期中转入数量、其中转入金额,期中转出数量、其中转出金额,期末数量、期末金额 

LNA023 项目号
LNA005 品号
LNA038 批号
LNA011 数量
LNA013 金额
LNA015 出入别(1,-1)
LNA006 日期
LNA007 仓库

第一种不需要仓库 按项目+品号+批号 汇总、 
 查询条件: 开始日期(期初日期)and 结束日期(期末日期)and 项目号

第二种需要仓库 按项目+品号+批号+仓库 汇总
查询条件: 开始日期(期初日期)and 结束日期(期末日期)and 项目号


------解决方案--------------------
declare @begindate datetime,
@enddate datetime,
@ID int,

1.
select 项目,品号,批号, sum(数量), sum(金额)
from JSKLNA
where 日期 between @begindate and @enddate
and 项目号 = @ID
group by 项目,品号,批号

2.
select 项目,品号,批号,仓库, sum(数量), sum(金额)
from JSKLNA
where 日期 between @begindate and @enddate
and 项目号 = @ID
group by 项目,品号,批号,仓库
------解决方案--------------------


ISNULL(sum(case when LNA015=1 then ISNULL(LNA013,0) end),0) AS LNA013R,

还没用过这样的语句呢。

学习一下,蛮复杂的。
------解决方案--------------------
探讨
谁顶我一下 我就给分 呵呵