最好的办法是将汽车列表存储为表格,其中包含以下数据:
Chevy
Ford
等等。
然后你可以通过加入做你想做的事:
select t.*,
max(case when cl.brand = 'Chevy' then 'this' end) as Chevy,
max(case when cl.brand = 'Ford' then 'this' end) as Ford,
. . .
from t left outer join
carlist cl
on left(t.col, length(cl.brand)) = cl.brand
group by t.id
否则,您必须处理数字:
select (case when left(col, locate('-', col) - 1) = carlist1 then 'this' end),
(case when left(col, locate('-', col) - 1) = carlist2 then 'that' end),
(case when left(col, locate('-', col) - 1) = carlist3 then 'foobar' end)