Mysql 在一次执行中更新多个列

Mysql 在一次执行中更新多个列,mysql,Mysql,使用下面的quwery将解决您的问题 UPDATE tblstoreitems SET price='499' WHERE TypeOrModel = 'A130'; UPDATE tblstoreitems SET price='599' WHERE TypeOrModel = 'A140'; UPDATE tblstoreitems SET price='1899' WHERE TypeOrModel = 'Alpha Style'; UPDATE tblstoreitems SET pri

使用下面的quwery将解决您的问题

UPDATE tblstoreitems SET price='499' WHERE TypeOrModel = 'A130';
UPDATE tblstoreitems SET price='599' WHERE TypeOrModel = 'A140';
UPDATE tblstoreitems SET price='1899' WHERE TypeOrModel = 'Alpha Style';
UPDATE tblstoreitems SET price='1699' WHERE TypeOrModel = 'Amethyst';
UPDATE tblstoreitems SET price='899' WHERE TypeOrModel = 'T18';
UPDATE tblstoreitems SET price='1499' WHERE TypeOrModel = 'Ace_f100';
UPDATE tblstoreitems SET price='499' WHERE TypeOrModel ='Aura Fusion';
UPDATE tblstoreitems SET price='499' WHERE TypeOrModel ='Axis';
UPDATE tblstoreitems SET price='499' WHERE TypeOrModel ='B100';    
UPDATE tblstoreitems SET price='499' WHERE TypeOrModel ='B5';    
UPDATE tblstoreitems SET price='499' WHERE TypeOrModel ='B8';
UPDATE tblstoreitems SET price='499' WHERE TypeOrModel ='Breeze';
UPDATE tblstoreitems SET price='499' WHERE TypeOrModel ='Breeze 2';
UPDATE tblstoreitems SET price='499' WHERE TypeOrModel ='Bubble';
UPDATE tblstoreitems SET price='499' WHERE TypeOrModel ='Burst 2.0';

我认为您正在使用不同的TypeOrModel值更新列price,如果您希望它位于一条语句中,您可以在更新中使用case,如下所示

update tblstoreitems
set price = 
case 
when TypeOrModel  = 'A130' then 499
when TypeOrModel  = 'A140' then 599
when TypeOrModel  = 'Alpha Style' then 1899
end

可以使用大小写表达式将这些更新替换为单个更新:

update tblstoreitems
set 
price = 
case 
 when TypeOrModel = 'A130' then '499'
 when TypeOrModel = 'A140' then '599'
 .......
 .......
 when TypeOrModel ='Burst 2.0' then '499'
end
质疑


非常感谢您的帮助或其他回复。。谢谢这将使任何未在WHE表达式中处理的型号的价格无效。
UPDATE tblstoreitems 
SET    price = CASE TypeOrModel
                WHEN 'A130' THEN '499'
                WHEN 'A140' THEN '599'
                -- All the others cases, snipped for clarity
                ELSE price END;
UPDATE tblstoreitems SET price=
CASE WHEN TypeOrModel IN 
(
    'A130','Aura Fusion','Axis','B100','B5','B8',
    'Breeze','Breeze 2','Bubble','Burst 2.0'
)
THEN 499
WHEN TypeOrModel IN ('A140') THEN 599
WHEN TypeOrModel IN ('Alpha Style') THEN 1899
WHEN TypeOrModel IN ('Amethyst') THEN 1699
WHEN TypeOrModel IN ('T18') THEN 899
WHEN TypeOrModel IN ('Ace_f100') THEN 1499
ELSE price
END;