注册 登录
编程论坛 SQL Server论坛

请教SQL查询一问题

mengland 发布于 2010-05-12 17:28, 630 次点击
如何从库房出入库流水账中查询出现有量?(item_code物料代码   inv入出库类型,其中:01采购入库增加库存 02领料出库减少库存 03其它出库减少库存   qty数量)
   item_code   inv   qty        
    001         01    20
    001         02     5
    002         01    10
    002         02     1
    002         03     5
    002         01    20
    002         02    15   
5 回复
#2
cnfarer2010-05-12 20:12
select item_code,sum(qty*(case inv when '01' then 1 else -1 end)) from table group by item_code
#3
mengland2010-05-13 08:42
谢谢! 如果入库和出库各有几种方式,如何写?
#4
cnfarer2010-05-13 12:35
回复 3楼 mengland
多几个when不就行了!
#5
mengland2010-05-13 15:18
谢谢!!!
#6
源本英明C2010-05-15 10:33
版主,请收我为徒吧!我也在做项目,以后在SQL SERVER 上肯定会遇到问题!
1