简体   繁体   English

如何正确的做如下update MYSQL语句?

[英]how to properly do the following update MYSQL statement?

i have a string with the following value我有一个具有以下值的字符串

Germany,Sweeden,UAE德国、瑞典、阿联酋

and i have an mysql row that have a value of one of this separated string with comma我有一个 mysql 行,它的值是这个用逗号分隔的字符串之一

as example a Country Row with a value Sweeden.例如,值为 Sweeden 的国家/地区行。

i have tried to use this sql statement to update a targeted row where its value is like one of this string separated with comma我曾尝试使用此 sql 语句来更新目标行,其中它的值就像这个用逗号分隔的字符串之一

hence if the row have a value of sweeden it should be updated sense sweeden value is include in the comma string因此,如果该行的值为 sweeden,则应该更新它,因为 sweeden 值包含在逗号字符串中

UPDATE CountryList SET Time= '100' WHERE Country LIKE '%Germany,Sweeden,UAE%' 

but i couldn't update the targeted row using this syntax.但我无法使用此语法更新目标行。 any idea what is the correct syntax i should use?知道我应该使用的正确语法是什么吗?

I think you want find_in_set() :我想你想要find_in_set()

update CountryList 
set time = 100 
where find_in_set(country, 'Germany,Sweeden,UAE')

This checks if country matches any of the values in the comma-separated row given as second argument to find_in_set() .这将检查country /地区是否与作为find_in_set()第二个参数给出的以逗号分隔的行中的任何值匹配。

Note that I removed the single quotes around the literal 100 : if time is a number, then treat it as such (if it's a string instead, then keep the quotes).请注意,我删除了文字100周围的单引号:如果time是一个数字,那么就这样对待它(如果它是一个字符串,那么保留引号)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM