使用Insert和Case的Sql语句

时间:2015-03-26 16:56:34

标签: php sql mysqli

我需要sql语句,允许我这样做:

update table set colomn1=val1 and colomn2=val2  when colomn1=value
else set colomn1=val11 and colomn2=val22  when colomn1=otherValue

请帮助

1 个答案:

答案 0 :(得分:2)

您可以尝试将CASE...WHEN用于更新声明

UPDATE table 
SET colomn1 = CASE WHEN colomn1 = value THEN value 
                   WHEN colomn1 = otherValue THEN val11 
                   ELSE somedefaultvalue END,
    colomn2 = CASE WHEN colomn1 = value THEN value2 
                   WHEN colomn1 = otherValue THEN val22  
                   ELSE somedefaultvalue END