案例陈述导致另一案件

时间:2014-07-14 17:47:21

标签: sql case

我需要将下面的逻辑组合起来并将其放在sql语句中。

逻辑:

CASE WHEN (ABC = 2)
        THEN  0
        ELSE  1
END XYZ

IF XYZ > 1
THEN 
FINAL_COLUMN = 10
ELSE 
FINAL_COLUMN = 20

SQL:

select (CASE WHEN(CASE ABC=2 then 0 Else 1 END AS) XYZ >123 
Then 10 ELSE 100 ) END AS FINAL_COLUMN  
from Table 1;

1 个答案:

答案 0 :(得分:0)

case语句的语法是

 Case 
     When Condition1 Then Value
     When Condition2 Then Value2
     Else Value
 End

所以你的陈述应该是

 Select CASE WHEN ABC = 2 Then 0 Else 1 End AS FINAL_COLUMN  from Table 1;