1

My table contains a column named "notes". I need to create a column Temper in my report. If I spot a word "angry" in the notes, then my new variable Temper should be 3. If I spot a word "indifferent" then Temper=2, otherwise Temper should equal to 0.

The initial table:

Id  State  Gender  Notes
1    IL     M      Kind of angry, but...
2    MI     F      Maybe indifferent also...
3    IL     F      Was cool but not necces...

The result should be like this:

    Id      Temper
    1          3
    2          2
    3          0

I am not sure how to do this in Teradata environment:

select Id, (notes like '%angry%')=3 else // ?????
from customers
where
case
4

1 回答 1

3

像这样的东西:

select id, 
       case 
         when notes like '%angry%' then 3
         when notes like '%indifferent%' then 2 
         else 0
       end as temper
from customers;
于 2013-09-10T20:51:53.573 回答