Update multiple rows with multiple 'where' clauses for each individual row

孤人 提交于 2019-11-27 19:47:37

give this a try by using CASE

Update  MyTable 
SET     value = CASE 
                     WHEN  game_id = 1 AND x = -4 AND y = 8 THEN 1
                     WHEN  game_id = 1 AND x = -3 AND y = 7 THEN 2
                     WHEN  game_id = 2 AND x =  5 AND y = 2 THEN 3
                     ELSE  value 
                END
WHERE   game_ID IN (1,2,3) AND  -- the purpose of this WHERE clause
        x IN (-4, -3, 5) AND    -- is to optimize the query by preventing from
        y IN (8,7,2)            -- performing full table scan.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!