MySQL UPDATE Multiple IF Conditions
I have a table which has been populated with incorrect data, so I n开发者_JAVA技巧eed to switch some numbers around. I'm not sure if this would be the best way to go about it, but I'm thinking about using an UPDATE statement with multiple IF conditions. Something like:
UPDATE
`orders`
SET
`orderPriority` = 1
IF(`orderPriority` = 2)
OR
`orderPriority` = 2
IF(`orderPriority = 3)
OR
`orderPriority` = 3
IF(`orderPriority` = 1);
Obviously this doesn't work, but my SQL skills are lacking here. Any help is appreciated!!!
UPDATE orders
SET orderPriority = CASE WHEN orderPriority = 1 THEN 3
WHEN orderPriority = 2 THEN 1
WHEN orderPriority = 3 THEN 2
END
WHERE orderPriority IN (1,2,3)
Yes, but what if you want to perform multiple conditional checks??
SET orderPriority = CASE WHEN ((field1 = 1) && (field2 = 2)) THEN 4
精彩评论