根据列值从单个表中选择多个间隔

时间:2014-02-19 07:07:00

标签: sql postgresql

我打算同时根据列值选择多个间隔。这是可能的           enter image description here

这是我的样本数据,它由1024行组成,我想根据波长列选择多个区间ex:(341-348)(551-664)(998-1021)来自单个表

2 个答案:

答案 0 :(得分:1)

您应该使用BETWEENOR来获取记录:

SELECT * FROM TABLE1 
   WHERE wavelenght BETWEEN 341 AND 348 
         OR wavelenght BETWEEN 551 AND 664  
         OR wavelenght BETWEEN 998 AND 1021  

答案 1 :(得分:0)

要查询不是特定值,而是查询一系列值,SQL为BETWEEN子句(http://www.w3schools.com/sql/sql_between.asp)发明了WHERE运算符,例如

SELECT columns
FROM yourtable
WHERE wavelength BETWEEN lowerbound AND upperbound;