user_car
car_id model_year brand_id
1 2006 1
2 2010 3
3 2015 2
4 2015 1
5 2015 1
和
car_brand
brand_id name
1 BMW
2 MAZADA
3 JEEP
如果我搜索“BMW2015”或“2015BMW”或“2015 BMW”
我无法在上面的sql查询中得到结果,我怎样才能以正确的方式搜索?
car_id brand_id model_year name
4 1 2015 BMW
5 1 2015 BMW
答案 0 :(得分:0)
如果我搜索" BMW2015"或" 2015BMW"意味着如果您搜索" BMW 2015"或" 2015宝马"意味着您手动拆分" "并尝试以下查询。
select * from user_car u inner join car_brand c on u.brand_id=c.brand_id where model_year like "%2015%" or model_year like "%BMW%" or name like "%2015%" or or name like "%BMW%" group by car_id order by car_id