如何进行将username
:
o
o
o
我在尝试:
select username from userinfo where username in('%o' , '%o%' , '%o')
但上述查询并未返回任何结果。这可能是什么原因?我怎么能得到结果?
答案 0 :(得分:2)
您必须使用LIKE
:
select username
from userinfo
where username LIKE '%o' OR username LIKE '%o%' OR username LIKE '%o'
或者,如果您没有位数据集并且正在寻找更简洁的语法,则可以使用REPLACE
:
select username
from userinfo
where REPLACE(username, 'o', '') <> username
答案 1 :(得分:1)
如评论中所述,您需要LIKE
运算符:
SELECT username
FROM userinfo
WHERE
username LIKE '%o' OR
username LIKE '%o%' OR
username LIKE '%o
答案 2 :(得分:1)
试试这个:
select username
from userinfo
where username like '%o'
OR username like '%o%'
OR username like '%o';
答案 3 :(得分:1)
您也可以尝试使用REGEXP
select username
from userinfo
WHERE username REGEXP 'o'
或喜欢
SELECT username FROM userinfo WHERE find_in_set('o', username)>0
答案 4 :(得分:1)
需要改进思考
包含o
之间的某处,包括开始和结束。所以你只需要
select username from userinfo where username like '%o%'