如何在mysql中执行批查询以获取更新列值

前端之家收集整理的这篇文章主要介绍了如何在mysql中执行批查询以获取更新列值 前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

例如,我有一个ACCOUNT WITH COLUMNS,ID和A_NUMBER表.
而且我想用不同的值更新单个查询中的A_NUMBER值.
“ UPDATE ACCOUNT SET A_NUMBER =” 0135“ WHERE ID = 131;
更新帐户集A_NUMBER =“ 0145” WHERE ID = 132;
UPDATE ACCOUNT SET A_NUMBER =“ 0155” WHERE ID = 133;
UPDATE ACCOUNT SET A_NUMBER =“ 0160” WHERE ID = 134;
UPDATE ACCOUNT SET A_NUMBER =“ 0175” WHERE ID = 135;
UPDATE ACCOUNT SET A_NUMBER =“ 0180” WHERE ID = 136;
UPDATE ACCOUNT SET A_NUMBER =“ 0195” WHERE ID = 137;
UPDATE ACCOUNT SET A_NUMBER =“ 0200” WHERE ID = 138;“

最佳答案
您应该使用“ CASE”语句:

UPDATE tbl SET A_NUMBER = CASE
WHEN id = 1 THEN ‘0135’
WHEN id = 2 THEN ‘0175’
...
END
WHERE id IN (1,2,...)
@H_502_21@

希望我有所帮助

原文链接:https://www.f2er.com/mysql/532130.html

猜你在找的MySQL相关文章