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

时间:2011-07-30 10:51:28

标签: php mysql sql

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

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 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)