0

如何在sql中使用if语句检查多个条件

在伪代码中

If survey_field is 1 and emp_code_field = 1 and post_field = 1 THEN set chance to 10
else if survey_field is 1 and emp_code_field = 1  THEN set chance to 5
survey_field is 1 THEN set chance to 1

我尝试了以下但我无法使用多个条件。

Update employee 
SET chance = 
CASE survey
WHEN 1  THEN 1

END

WHERE 1
4

1 回答 1

1

你可以这样试试。。

 UPDATE employee 
    SET chance = Case when
    ( survey_field=1) AND (emp_code_field = 1) AND (post_field = 1) THEN 10
    ELSE 
    WHEN (survey_field =1) AND (emp_code_field = 1)  THEN 5
    ELSE
    WHEN
    survey_field = 1 THEN  1
    END
于 2013-05-07T16:46:54.983 回答