我的数据由1024行和2列组成。它的结构类似于
我想根据第一列从单个表中选择三个区间。在选定的时间间隔内,第二列值应乘以值
SELECT * FROM del
WHERE wavelength BETWEEN 341 AND 348
OR wavelength BETWEEN 551 AND 664
OR wavelength BETWEEN 998 AND 1021
在这一个中,使用此查询和
选择间隔在乘法后,我想在第二列中显示波长和相乘的反射率值
答案 0 :(得分:2)
试试这个:
SELECT wavelength,
CASE WHEN wavelength BETWEEN 551 AND 664 THEN reflectance * .5
ELSE reflectance * .25
END AS 'REFLECTANCE'
FROM del
WHERE wavelength BETWEEN 341 AND 348
OR wavelength BETWEEN 551 AND 664
OR wavelength BETWEEN 998 AND 1021
或常见的选择:
SELECT wavelength,
CASE WHEN (wavelength BETWEEN 341 AND 348)
OR (wavelength BETWEEN 998 AND 1021) THEN reflectance * .25
WHEN wavelength BETWEEN 551 AND 664 THEN reflectance * .5
ELSE 1 ---(PUT YOUR DEFAULT)
END AS 'REFLECTANCE'
FROM del
答案 1 :(得分:1)
第一个和第三个范围乘以0.25
,第二个范围乘以0.5
您可以使用以下查询。
SELECT wavelength,
( reflect * 0.25 ) AS reflect
FROM wavelength
WHERE ( wavelength BETWEEN 341 AND 348 )
OR ( wavelength BETWEEN 998 AND 1021 )
UNION ALL
SELECT wavelength,
( reflect * 0.5 ) AS reflect
FROM wavelength
WHERE wavelength BETWEEN 551 AND 664;
如果要将所有三个乘以不同的值,则可以使用
SELECT wavelength,
( reflect * 0.25 ) AS reflect
FROM wavelength
WHERE wavelength BETWEEN 341 AND 348
OR wavelength BETWEEN 998 AND 1021
UNION ALL
SELECT wavelength,
( reflect * 0.5 ) AS reflect
FROM wavelength
WHERE wavelength BETWEEN 551 AND 664
UNION ALL
SELECT wavelength,
( reflect * 0.25 ) AS reflect
FROM wavelength
WHERE wavelength BETWEEN 998 AND 1021