简体   繁体   English

在MYSQL中具有大小写的更新语句

[英]Update Statement with Case in MYSQL

I have this issue and I have investigated more than five house but find nothing :( . I have table called support. 我有这个问题,已经调查了五栋以上的房屋,但一无所获:(。我有一张桌子叫做support。

UPDATE support s SET    s.Survey_Status = 0
CASE 
WHEN s.Survey_Status = 0 Then 1
WHEN s.Survey_Status = 1 Then 2 
End 
Where last_response < ADDDATE(CURDATE(), INTERVAL 1 DAY) 
and support_waiting ="n" ;

I need to update the support table and set the survey_status =1 except the fifth row in the table will be =2 . 我需要更新支持表并设置Survey_status = 1,除非表中的第五行是= 2。 For example, if I have survey_ status from 1 to 10 = 1 then the fifth will =2 . 例如,如果我的Survey_ status从1到10 = 1,则第五个将= 2。 any idea please ?? 任何想法请?? By the way, I am working with mysql Heidi . 顺便说一下,我正在使用mysql Heidi。

Thanks in Advance 提前致谢

You can combine user variables and MOD() : 您可以结合用户变量MOD()

UPDATE   support, (SELECT @r:=0) init
SET      Survey_Status = IF(MOD(@r:=@r+1,5), 1, 2)
WHERE    last_response < CURRENT_DATE + INTERVAL 1 DAY
     AND support_waiting = 'n'
ORDER BY ...

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

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