使用LIKE在MySQL中很常见.我们这样使用它:WHERE field LIKE '%substring%'.我们有一个子字符串,字段有完整的字符串.但我需要的是相反的事情.我在现场有子串.所以,我想要包含字符串子串的行.假设该表是:
----+-------------------
id | keyword
----+-------------------
1 | admission
----+-------------------
2 | head of the dept
----+-------------------
Run Code Online (Sandbox Code Playgroud)
我有一个来自用户的字符串:Tell me about admission info.我需要这样一个MySQL查询返回,admission因为这是用户字符串的子字符串.就像是:
SELECT keyword FROM table WHERE (keyword is a substring of 'Tell me about admission info')
Run Code Online (Sandbox Code Playgroud)
提前致谢.
Adr*_*der 17
你正在寻找LIKE运算符
模式匹配使用SQL简单正则表达式比较.返回1(TRUE)或0(FALSE).如果expr或pat为NULL,则结果为NULL.
就像是
SELECT keyword
FROM table
WHERE ('Tell me about admission info' LIKE CONCAT('%', keyword, '%'))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
39909 次 |
| 最近记录: |