1

我在一列上有 5 个不同的范围数据,我要在上面放置过滤器

10-20 
110-120 
250-260

我在下面使用,但它的结果不正确。

Select * from test where
testnumber between '10' and '20'
or testnumber between '110' and '120'
or testnumber between '250' and '260'

有人可以建议我如何在 SQL 中实现这个或正确的方法来做到这一点。谢谢

4

3 回答 3

1

尝试这个:

select * from test where testnumber between ('10') and ('20')
于 2013-07-01T20:46:13.787 回答
1

如果您可以将您的范围放入包含BeginNumEndNum列的表格中,您可以这样做

SELECT * 
FROM test t
INNER JOIN Ranges r on t.testnumber BETWEEN r.BeginNum and r.EndNum
于 2013-07-01T20:50:17.740 回答
0

即使您无法创建表,您也可能有其他一些选择:

Select *
from (values(1),(15),(50),(115),(200),(255),(300)) test(testnumber)
where testnumber between '10' and '20'
or testnumber between '110' and '120'
or testnumber between '250' and '260'

或者

declare @test (testnumber int);
insert @test values(1),(15),(50),(115),(200),(255),(300);

Select *
from @test
where testnumber between '10' and '20'
or testnumber between '110' and '120'
or testnumber between '250' and '260'
于 2013-07-01T21:35:00.970 回答