让我说我做select score from table1
。这将返回结果从表格列结果显示sql自定义文本
score
----
0
20
40
如何使用的情况下,将输出更改到如果0->坚决不同意20-> 40-同意>非常同意
让我说我做select score from table1
。这将返回结果从表格列结果显示sql自定义文本
score
----
0
20
40
如何使用的情况下,将输出更改到如果0->坚决不同意20-> 40-同意>非常同意
我想这就是你想要的东西:
select
case
when score >= 40 then 'very agreed'
when score >= 20 then 'agree'
else 'strongly not agree'
end
from table1
我不知道如果我理解正确的问题,但也许这就是你想要什么:
select decode(score,0,'Strongly not agreed',20,'Agree',40,'Very Agreed') from table1
case when score < 20 then 'Strongly Not Agreed'
when score between 20 and 40 then 'Agree'
when score > 40 then 'Strongly Agreed' end
当得分= 40时,这会产生错误的输出。 – 2010-07-07 09:40:48
这并不固定值的简单翻译:
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分支是可选的,但我已经包括它来处理空值或意外值。如果您的数据模型执行适当的约束,您可能不需要它。
假设他不想要任何范围,我认为这是最好的解决方案。 – 2010-07-07 09:19:47