tags:

views:

43

answers:

4

let say i do select score from table1. this will return result

score
----
0
20
40

how to use case, to change the output to if 0->strongly not agree 20->agree 40->very agreed

+3  A: 

I think thats what you want:

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

I'm not sure if I understand the question correctly but maybe this is what you want:

select decode(score,0,'Strongly not agreed',20,'Agree',40,'Very Agreed') from table1
Rene
Assuming he does not want any ranges, I think this is the best solution.
inflagranti
+1  A: 
case when score < 20               then 'Strongly Not Agreed'
     when score between 20 and 40  then 'Agree'
     when score > 40               then 'Strongly Agreed' end
ar
This produces the wrong output when score = 40.
Janek Bogucki
+4  A: 

This does a simple translation of fixed values:

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
/

If you are working with ranges the syntax is slightly different:

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
/

The ELSE branch is optional but I have included it to handle NULLs or unexpected values. If your data model enforces the appropriate constraints you might not need it.

APC