Sql 使用空值进行阈值比较
我们正在构建一个报告,其中一些值与阈值进行比较。逻辑是Sql 使用空值进行阈值比较,sql,oracle,threshold,Sql,Oracle,Threshold,我们正在构建一个报告,其中一些值与阈值进行比较。逻辑是 if value > lower_threshold and value < upper_threshold then PASS else FAIL if value>lower\u threshold和value
if value > lower_threshold and value < upper_threshold then PASS else FAIL
if value>lower\u threshold和value
但是,对于某些参数,上限_阈值设置为NULL。这基本上意味着没有上限阈值,如果值下限阈值和值这不是一个好办法。有没有其他方法可以达到同样的效果?
或
:
if value > lower_threshold and (value < upper_threshold or upper_threshold is null) then PASS else FAIL
想到
或
:
if value > lower_threshold and (value < upper_threshold or upper_threshold is null) then PASS else FAIL
不完全是你想要的,因为较低的范围是包含的,但是也许你可以考虑语法(需要12.1或更高的时间)。 结果:
select * from demo_ranges as of period for threshold_range 100;
DESCRIPTION LOWER_THRESHOLD UPPER_THRESHOLD
-------------------- --------------- ---------------
Orange 100 200
select * from demo_ranges as of period for threshold_range 1000;
DESCRIPTION LOWER_THRESHOLD UPPER_THRESHOLD
-------------------- --------------- ---------------
Red 200
内部构建了与戈登的答案相同的SQL(您可以用“代码> dBMSUntudio.ExpExpQSQLXTEX/<代码>确认”。
不完全是您想要的,因为较低的范围是包含的,但也许您可以考虑语法(需要12.1或更高版本)。
结果:select * from demo_ranges as of period for threshold_range 100;
DESCRIPTION LOWER_THRESHOLD UPPER_THRESHOLD
-------------------- --------------- ---------------
Orange 100 200
select * from demo_ranges as of period for threshold_range 1000;
DESCRIPTION LOWER_THRESHOLD UPPER_THRESHOLD
-------------------- --------------- ---------------
Red 200
在内部,它构建了与Gordon回答中相同的SQL(您可以使用
dbms\u实用程序来确认这一点。展开\u SQL\u text
)。您的帖子被标记为SQL
。在哪里使用if语句?SQL中没有这样的东西。您的帖子被标记为SQL
。在哪里使用if语句?SQL中没有这样的东西。
select * from demo_ranges as of period for threshold_range 100;
DESCRIPTION LOWER_THRESHOLD UPPER_THRESHOLD
-------------------- --------------- ---------------
Orange 100 200
select * from demo_ranges as of period for threshold_range 1000;
DESCRIPTION LOWER_THRESHOLD UPPER_THRESHOLD
-------------------- --------------- ---------------
Red 200