我在一列上有 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 中实现这个或正确的方法来做到这一点。谢谢
我在一列上有 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 中实现这个或正确的方法来做到这一点。谢谢
尝试这个:
select * from test where testnumber between ('10') and ('20')
如果您可以将您的范围放入包含BeginNum
和EndNum
列的表格中,您可以这样做
SELECT *
FROM test t
INNER JOIN Ranges r on t.testnumber BETWEEN r.BeginNum and r.EndNum
即使您无法创建表,您也可能有其他一些选择:
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'