我如何使用case语句创建行值

时间:2019-06-10 14:00:33

标签: oracle

我正在尝试使用类似case的语句为一列创建多个4行值:

Case when time_zero = '00' then 'zero' case when time_zero ='01' then 'zeroOne' case when Day_of_Year ='Today' then '2day' when Day_of_Year ='yesterday' then 'yesterday end end as Ouput_column

这是针对oracle 11g

Case when time_zero = '00' then 'zero' case when time_zero ='01' then 'zeroOne' case when Day_of_Year ='Today' then '2day' when Day_of_Year ='yesterday' then 'yesterday end end as Output_column

预期结果Output_column

zeroOne
2day
zero
yesterday

1 个答案:

答案 0 :(得分:0)

这将创建新列:

select *,
  case 
     when time_zero = '00' then 'zero'
     when time_zero ='01' then 'zeroOne'
     when Day_of_Year ='Today' then '2day' 
     when Day_of_Year ='yesterday' then 'yesterday' 
  end as Output_column
from tablename

该列的值首先取决于列time_zero的值,其次取决于列Day_of_Year的值。
如果没有任何条件适用,则为null