批量更新MySQL数据的方法
楼上误人子弟 啊,不懂就不要说了,把多个结果结果集生成 一个表,多表关联更新,还可以用case where 方法1(我更倾向于方法1).UPDATE table1,
(SELECT 1 AS id, 1 AS scoreA, 2 AS scoreB
UNION ALL SELECT 1 AS id,91 AS scoreA,98 AS scoreB
UNION ALL SELECT 2 AS id,92 AS scoreA,97 AS scoreB) temp
SET table1.scoreA = temp.scoreA, table1.scoreB = temp.scoreB
WHERE table1.id = temp.id ;方法2.UPDATE table1
SET scoreA= CASE id
WHEN 10001 THEN 98
WHEN 10002 THEN 97
WHEN 10004 THEN 92
WHEN 10006 THEN 92
WHEN 10039 THEN 93
END
WHERE
id IN ( 10001, 10002, 10004, 10006, 10039 )
赞0
踩0