有没有其他方法可以代替"lt"在CASE语句中?
那是我的桌子:
create table table (id, numbrr) as
select 1, 450 from dual union all
select 2, 120 from dual union all
select 33, 130 from dual ;
那是我的sql脚本:
select id, number, case when numbrr < 400 then 'Yes' end result
from table
在真实的表中,我有很多数据,不会使用这个脚本(我不能用手写那么多数据(
case when number in (120,130) then 'Yes' end result
您也可以使用sign
函数:sign(numbrr - 400) = -1
,它不会对下边界施加任何限制(您在问题中没有声明(。此函数返回-1、0和1,具体取决于表达式相对于0的值。
select id, numbrr, case when sign(numbrr - 400) = -1 then 'Yes' end as result from input_tab
使用此样本数据
create table input_tab (id, numbrr) as select 1, 450 from dual union all select 2, 120 from dual union all select 33, 130 from dual union all select 4, -10 from dual
返回
ID 是 1 450 null 33 130是 4 -10是 您可以使用BETWEEN子句:
select id, number, case when number between 0 and 400 then 'Yes' end result from table1;
谢谢