2010-07-07 27 views

回答

4

我想这就是你想要的东西:

select 
    case 
    when score >= 40 then 'very agreed' 
    when score >= 20 then 'agree' 
    else 'strongly not agree' 
    end 
from table1 
2

我不知道如果我理解正确的问题,但也许这就是你想要什么:

select decode(score,0,'Strongly not agreed',20,'Agree',40,'Very Agreed') from table1 
+0

假设他不想要任何范围,我认为这是最好的解决方案。 – 2010-07-07 09:19:47

1
case when score < 20    then 'Strongly Not Agreed' 
    when score between 20 and 40 then 'Agree' 
    when score > 40    then 'Strongly Agreed' end 
+0

当得分= 40时,这会产生错误的输出。 – 2010-07-07 09:40:48

4

这并不固定值的简单翻译:

select score 
     , case score 
       when 0 then 'strongly not agree' 
       when 20 then 'agree' 
       when 40 then 'very agreed' 
       else 'don''t know' 
     end as txt 
from your_table 
/

如果您正在使用范围工作的语法稍有不同:

select score 
     , case 
       when score between 0 and 19 then 'strongly not agree' 
       when score between 20 and 39 then 'agree' 
       when score >= 40 then 'very agreed' 
       else 'don''t know' 
     end as txt 
from your_table 
/

else分支是可选的,但我已经包括它来处理空值或意外值。如果您的数据模型执行适当的约束,您可能不需要它。