表A
:
id book_title
-----------------
1 Harry,Potter
2 Limitless
案例1:
select * from A where book_title like '%Harry%'
Output:
1 Harry,Potter
它有效
但是在案例2中:
select * from A where book_title like '%HarryPotter%'
Output:
<Nothing>
当然,因为这个参数必须与HarryPotter匹配。
是否有任何sql语句可以显示如下输出:
Parameter: HarryPotter
SQL: ?
Output: 1 Harry,Potter
感谢。
答案 0 :(得分:3)
在执行LIKE
时,首先使用REPLACE
从book_title中移除任何,
:
select * from A where replace(book_title,',','') like '%HarryPortter%'
答案 1 :(得分:1)
只需在where语句中插入逗号或使用%,如果您不确定,这两个词之间是什么:
select * from A where book_title like '%Harry%Portter%'
答案 2 :(得分:1)
在这种情况下,您需要find_in_set功能尝试类似
SELECT ... WHERE FIND_IN_SET('Harry', field)