SQL 中批量更新应该怎么写?
資深大佬 : mebtte 4
比如我有一个表 { id: int, order: int } , 现在想批量更新, 比如 id=1 set order=2, id=2 set order=3 , id 和 order 对应的值是外面传进来的, 一条 update 语句能做到吗?
大佬有話說 (14)
比如我有一个表 { id: int, order: int } , 现在想批量更新, 比如 id=1 set order=2, id=2 set order=3 , id 和 order 对应的值是外面传进来的, 一条 update 语句能做到吗?
….
else
end
)
““
数据量大时 ods 应改为使用临时表导入。
SELECT @row := @row + 1 AS id FROM
(select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) t1,
(SELECT @row:=0) t
on duplicate key update `order` = `id`;
“`