简体   繁体   English

在SQL语句中使用if使用多个条件

[英]Using multiple conditions using if in sql statement

How do I check multiple conditions using an if statement in sql 如何在SQL中使用if语句检查多个条件

In pseudocode 用伪代码

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

I have tried the following but I am not able to use multiple conditions . 我尝试了以下方法,但无法使用多个条件。

Update employee 
SET chance = 
CASE survey
WHEN 1  THEN 1

END

WHERE 1

You can try like this.. 你可以这样尝试

 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM