我希望通过第二个字
来搜索通配符这里有一些列数据
sea food
food restaurant
Chinese food
如果我搜索“foo”。它应该返回
sea food
Chinese food
我怎么能在MySQL中做到这一点
答案 0 :(得分:1)
怎么样: -
select * from table where food_name like '% foo%'
答案 1 :(得分:0)
在你的SQL查询中使用regexp ..类似
select * from table where col regexp '^[A-Za-z]+\s(foo).*$'
修改
用过你的桌子..试试这个......
select id,col from food where col regexp '^[A-Za-z]+ (foo)'
答案 2 :(得分:0)
使用以下查询。这对你的情况有帮助。
select column-name-list from table-name
where right(your-desired-column-name,4) = 'food';
答案 3 :(得分:0)
这是一种做法
select * from
test
where
substring_index(food_name,' ',-1) like '%foo%'
AND
(
LENGTH(food_name) - LENGTH( substring_index(food_name,' ',-1)) > 0
)
;
<强> DEMO 强>