是否有更快的方法来编写这3个相同的查询?

时间:2022-02-25 21:29:15

Is there any faster query way of rewriting these queries or by combining them?

是否有更快的查询方式来重写这些查询或组合它们?

update products
set shop = '1' 
where shop LIKE '%demo%'

update products
set shop = '2' 
where shop LIKE '%car%'

update products
set shop = '3' 
where shop LIKE '%art%'

2 个解决方案

#1


4  

update products
set shop =
case 
when shop like '%demo%' then 1
when shop like '%car%' then 2
when shop like '%art%' then 3
else shop
end

#2


0  

Maybe a stored procedure: http://www.sqlinfo.net/mysql/mysql_stored_procedure_UPDATE.php

也许是一个存储过程:http://www.sqlinfo.net/mysql/mysql_stored_procedure_UPDATE.php

#1


4  

update products
set shop =
case 
when shop like '%demo%' then 1
when shop like '%car%' then 2
when shop like '%art%' then 3
else shop
end

#2


0  

Maybe a stored procedure: http://www.sqlinfo.net/mysql/mysql_stored_procedure_UPDATE.php

也许是一个存储过程:http://www.sqlinfo.net/mysql/mysql_stored_procedure_UPDATE.php