gpt4 book ai didi

sql - 用一个查询更新多行?

转载 作者:IT老高 更新时间:2023-10-28 23:45:54 24 4
gpt4 key购买 nike

我在这里找到了可以更新一个字段的东西:http://www.karlrixon.co.uk/articles/sql/update-multiple-rows-with-different-values-and-a-single-sql-query/

UPDATE person
SET name = CASE id
WHEN 1 THEN 'Jim'
WHEN 2 THEN 'Mike'
WHEN 3 THEN 'Precious'
END
WHERE id IN (1,2,3)

我的问题是如何更新多个字段?如:

UPDATE person
SET name = CASE, sex = CASE id
WHEN 1 THEN 'Jim', 'female'
WHEN 2 THEN 'Mike', 'male'
WHEN 3 THEN 'Precious', 'male'
END
WHERE id IN (1,2,3)

这当然行不通。尝试了其他一些组合并失败了。任何想法?谢谢!

最佳答案

UPDATE person
SET name = CASE id
WHEN 1 THEN 'Jim'
WHEN 2 THEN 'Mike'
WHEN 3 THEN 'Precious'
END,
sex = CASE id
WHEN 1 THEN 'female'
WHEN 2 THEN 'male'
WHEN 3 THEN 'male'
END
WHERE id IN (1,2,3)

关于sql - 用一个查询更新多行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2528181/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com