我有一张这样的不同包装的表:
term package1 package2 package3
1yr 1000 2000 3000
2yr 1800 3800 5800
3yr 2500 5500 7500
现在,我想选择值在a和b之间的所有行。
我尝试使用这个:
SELECT * FROM Products WHERE package1, package2 BETWEEN 1000 AND 5000
答案 0 :(得分:1)
如果要让行中的任何值介于1000到5000之间,则需要测试它们中的每一个并与OR
组合:
SELECT * FROM Products
WHERE package1 BETWEEN 1000 AND 5000
OR package2 BETWEEN 1000 AND 5000
OR package3 BETWEEN 1000 AND 5000
如果要让行 all 的值在范围内,请将OR
更改为AND
。
答案 1 :(得分:1)
有两种方法可以实现此目的。在或>和<符号as explained here
之间使用答案 2 :(得分:0)
不幸的是,我认为您将不得不执行多个where语句,例如:
SELECT * FROM Products
WHERE (package1 BETWEEN 1000 AND 5000) OR
(package2 BETWEEN 1000 AND 5000) OR
package3 BETWEEN 1000 AND 5000
或者如果您需要所有软件包年份都在该行的那些值之内:
WHERE (package1 BETWEEN 1000 AND 5000) AND
(package2 BETWEEN 1000 AND 5000) AND
package3 BETWEEN 1000 AND 5000
答案 3 :(得分:0)
您的查询应针对与和组合的每个列
SELECT * FROM Products
WHERE (package1 BETWEEN 1000 AND 5000)
And (package2 BETWEEN 1000 AND 5000)
And (package3 BETWEEN 1000 AND 5000);