【发布时间】:2014-10-02 11:31:50
【问题描述】:
我有一个类似This is a computer 的查询字符串。我在数据库中有一些词,例如computer、This、machine。
我想找到查询字符串的子字符串。对于上面的例子,我会得到This和computer。
mysql语句怎么写?
【问题讨论】:
我有一个类似This is a computer 的查询字符串。我在数据库中有一些词,例如computer、This、machine。
我想找到查询字符串的子字符串。对于上面的例子,我会得到This和computer。
mysql语句怎么写?
【问题讨论】:
您可以使用INSTR() 函数执行以下操作
SELECT * FROM your_table
WHERE INSTR('This is a computer', word) > 0
【讨论】:
SELECT
words
FROM
table_with_words
WHERE 'This is a computer' LIKE CONCAT('%', words, '%');
【讨论】:
如果表中有很多单词,mb,最好使用这样的查询:
SELECT word
FROM table_with_words
WHERE FIND_IN_SET(word, REPLACE('This is a computer', ' ', ',')) != 0
【讨论】: