0

我知道这不起作用:

UPDATE `states` SET `country_id` = '83', `position` = (1,2,3) WHERE `states`.`id` IN (381, 378, 380);

有没有办法根据

id = 381; position = 1
id = 378; position = 2
id = 380; position = 3

谢谢。

4

1 回答 1

3

最简单的是使用三个单独的查询。

单个查询是可能的,但更复杂:

UPDATE states
SET country_id = '83',
    position = CASE id WHEN 381 THEN 1
                       WHEN 378 THEN 2
                       WHEN 370 THEN 3 END
WHERE id IN (381, 378, 380)
于 2012-04-18T16:31:40.427 回答