在MySQL中使用on查询更新多个列

在MySQL中使用on查询更新多个列,mysql,mysql-workbench,Mysql,Mysql Workbench,我需要在我的表“customers”中使用1 CASE命令如下设置city_populations列 Barrie = 177,061 Toronto = 2,480,000 Collingwood = 17,290 Thunder Bay = 108,359 我创建了两个查询,但它不会运行,没有任何建议 UPDATE customers SET city_population Barrie = 177061, Tor

我需要在我的表“customers”中使用1 CASE命令如下设置city_populations列

Barrie      =   177,061
Toronto     =   2,480,000
Collingwood =   17,290
Thunder Bay =   108,359
我创建了两个查询,但它不会运行,没有任何建议

UPDATE customers
SET city_population Barrie = 177061, 
                    Toronto = 2480000,
                    Collingwood = 17290, 
                    Thunder Bay =108359 
WHERE city = 'Barrie', 'Toronto', 'Collingwood', 'Thunder Bay';

 UPDATE customers
 SET city_population = 177061, 2480000, 17290, 108359 
 WHERE city = 'Barrie', 'Toronto', 'Collingwood', 'Thunder Bay';

试着用这样的东西

UPDATE `customers`
SET `city_population` = CASE `city`
WHEN 'Barrie' THEN 177061
WHEN 'Toronto' THEN 2480000
....
END,
WHERE `customers` IN ('Barrie', 'Toronto', ...);

您的表格中有Barrie、Toronto、Collingwood和Thunder Bay列,或者似乎是表格中的行。哪个是哪个?是的,城市列包含这些城市,并且已经创建。我必须创建一个城市人口专栏,我做到了。知道我必须用查询中给定的人口填充city_population中的这些城市。city是一行,city name是一列。此外,city_population是行,number of population是列,您可以发布四个不同的更新。听起来你不会不止一次这样做。没问题,而且编码很愉快!
UPDATE `customers`
SET city_population = CASE city
WHEN 'Barrie' THEN 177061
WHEN 'Toronto' THEN 2480000
WHEN 'Collingwood' THEN 17290
WHEN 'Thunder Bay' THEN 108359  
END
WHERE `city` IN ('Barrie', 'Toronto', 'Collingwood', 'Thunder Bay');