例如,我有一个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”语句:
原文链接:https://www.f2er.com/mysql/532130.htmlUPDATE tbl SET A_NUMBER = CASE WHEN id = 1 THEN ‘0135’ WHEN id = 2 THEN ‘0175’ ... END WHERE id IN (1,2,...)
@H_502_21@希望我有所帮助