【问题标题】:MySQL find result that is substring of a query stringMySQL查找结果是查询字符串的子字符串
【发布时间】:2014-10-02 11:31:50
【问题描述】:

我有一个类似This is a computer 的查询字符串。我在数据库中有一些词,例如computer、This、machine。

我想找到查询字符串的子字符串。对于上面的例子,我会得到This和computer。

mysql语句怎么写?

【问题讨论】:

    标签: mysql database select


    【解决方案1】:

    您可以使用INSTR() 函数执行以下操作

    SELECT * FROM your_table
    WHERE INSTR('This is a computer', word) > 0
    

    【讨论】:

      【解决方案2】:
      SELECT
      words
      FROM
      table_with_words
      WHERE 'This is a computer' LIKE CONCAT('%', words, '%');
      

      【讨论】:

        【解决方案3】:

        如果表中有很多单词,mb,最好使用这样的查询:

        SELECT word
        FROM table_with_words
        WHERE FIND_IN_SET(word, REPLACE('This is a computer', ' ', ',')) != 0
        

        【讨论】:

          猜你喜欢
          • 2013-07-05
          • 1970-01-01
          • 2012-09-07
          • 1970-01-01
          • 1970-01-01
          • 2013-10-22
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多