现有张表,表结构及数据类似如下:
date itemnumber lotnumber actiontype receiptqty reversedqty rerunqty
5/10 100010 x07 v null 200 null
5/14 100010 x07 r 5000 null null7/6 100010 x07 x null null 800
.
.
.
.
.
现在要:当itemnumber和lotnumber相同的情况下,用actiontype为r的receiptquantity减去actiontype为v的reversedquantity和
actiontype为x的rerunquantity,如上面的就是:5000-200-800;再取出actiontype为r的date,如上就是:5/14/2007 .同时取出itemnumber和lotnumber.请叫各位高人.谢谢!
date itemnumber lotnumber actiontype receiptqty reversedqty rerunqty
5/10 100010 x07 v null 200 null
5/14 100010 x07 r 5000 null null7/6 100010 x07 x null null 800
.
.
.
.
.
现在要:当itemnumber和lotnumber相同的情况下,用actiontype为r的receiptquantity减去actiontype为v的reversedquantity和
actiontype为x的rerunquantity,如上面的就是:5000-200-800;再取出actiontype为r的date,如上就是:5/14/2007 .同时取出itemnumber和lotnumber.请叫各位高人.谢谢!
解决方案 »
- 求一个SQL语句
- SQL小问题
- 【问】:查询语句中同时使用sum,max 怎么处理?
- 继续提问.板箱个数问题
- 帮帮忙,一个查询不会写,谢谢大家![急]
- sql server2000内如何把varchar类型改成text类型,急救命啊!!!!!!!!!!!!!!
- SQL 2012系统管理方面问题,内存及客户资源管理
- 怎么样把.sql文件,转换成可以用数据库表直观的显示表类型!
- Access中怎样写日期类型的条件,如select * from table where Date > '2001-7-28',说不对
- sqlserver 和 oracle 查询语句的过滤顺序
- 求一条sql语句,谢谢,关于条件查询的
- 我iis装了,sql 2000也装了,为什么访问127.0.0.1是空白的啊?本机xp!!
(select isnull(receiptqty, 0) from 表
where itemnumber = t.itemnumber and lotnumber = t.lotnumber and actiontype = r) -
(select isnull(reversedqty, 0) from 表
where itemnumber = t.itemnumber and lotnumber = t.lotnumber and actiontype = v) -
(select isnull(rerunqty, 0) from 表
where itemnumber = t.itemnumber and lotnumber = t.lotnumber and actiontype = x)
from 表 t
where actiontype = r這樣?
from t a
where t.itemnumber=a.itemnumber and t.lotnumber=a.lotnumber