如何组合具有不同where条件的两个更新查询

时间:2016-02-21 08:15:06

标签: mysql sql

如何组合这两个更新语句:

update Special_quota set Status=0,Additional_msg_quota=0 where User_id not  in('1','2','3') 

update Special_quota set Status=1,Additional_msg_quota=30 where User_id in('1','2','3')

2 个答案:

答案 0 :(得分:2)

您可以像这样使用CASE表达式:

UPDATE Special_quota 
set Status = CASE WHEN User_ID IN('1','2','3') then 1 else 0 end,
    additional_msg_quota = CASE WHEN User_ID IN('1','2','3') then 30 else 0 end

答案 1 :(得分:1)

UPDATE Special_quota
set Status = CASE WHEN User_ID IN('1','2','3') then 1 else 0 end,
    Additional_msg_quota = CASE WHEN User_ID IN('1','2','3') then 30 else 0 end