读书人

求一条SQL2000 话语

发布时间: 2012-09-01 09:33:03 作者: rapoo

求一条SQL2000 语句

单号 物品编号 重量
001 201 3
001 202 4
002 203 8
002 201 1
002 202 5
003 203 8
004 201 2
004 202 3
004 203 7
005 201 2
005 202 3
005 204 9
006 201 4
006 202 5


求:以任意一个单号的两个物品编号和重量做为条件,查询包含或等于该两种相同物品且重量在正负N范围内的单号。


[解决办法]

探讨

引用:

select * from
(select * from t_a where nameid='202' and heavy between @heavy-@f and @heavy+@f) a,
(select * from t_a where nameid='202' and heavy between @heavy-@f and @heavy+@f) b
……

读书人网 >SQL Server

热点推荐