情况1:
SQL Server:
select (case a1 when '0' then 'easy'
when '1' then 'normal'
when '2' then 'hard' end) level
from a;
Oracle:
select decode(a1,'0', 'easy', '1', 'normal', '2', 'hard') level from a;
情况2:
SQL Server:
select (case when a1 between 0 and 60 then 'no pass'
when a1 between 61 and 80 then 'normal'
when a1 between 81 and 100 then 'good' end) level
from a;
Oracle:
select decode(sign(a1-61),-1, 'no pass',decode(sign(a1-81),-1, 'normal', 'good') level from a;备注:
decode的用法是decode(表达式,期待值1,转换值1, 期待值2,转换值2,……)
sign的用法是sign(表达式),如果表达式<0则函数返回-1,如果表达式=0则函数返回0,如果表达式>0则函数返回1.