要实现批量更新SQL,可以使用以下方法:
UPDATE your_table
SET column1 =
CASE
WHEN condition1 THEN value1
WHEN condition2 THEN value2
ELSE column1
END,
column2 =
CASE
WHEN condition1 THEN value3
WHEN condition2 THEN value4
ELSE column2
END
WHERE your_condition;
UPDATE your_table
SET column1 = subquery.column1,
column2 = subquery.column2
FROM (
SELECT id, new_value1 AS column1, new_value2 AS column2
FROM your_table
WHERE your_condition
) AS subquery
WHERE your_table.id = subquery.id;
UPDATE your_table
SET column1 = another_table.new_value1,
column2 = another_table.new_value2
FROM your_table
JOIN another_table ON your_table.id = another_table.id
WHERE your_condition;
以上是几种常用的实现批量更新SQL的方法,具体应用取决于数据的结构和更新的逻辑。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: 如何评估SQL数据恢复的成功率