MySQL在哪里用逗号表示

时间:2016-05-23 07:39:40

标签: mysql

如何按SELECT ... WHERE LIKE显示带有字段的结果?

我已尝试过此SELECT * FROM tbl_question WHERE word LIKE '%How are you?%',但它无法正常使用。

tbl_question

+-------------+-------------------+------------+
| question_id | question          | word       |
+-------------+-------------------+------------+
| 1           | How are you?      | How        |
| 2           | What's your name? | What, name |
| 3           | Hi there!         | Hi         |
| 4           | Hi, How are you?  | Hi, How    |
+-------------+-------------------+------------+

示例:如果我搜索"How are you?",它将显示2行的结果,如:

+-------------+-------------------+------------+
| question_id | question          | word       |
+-------------+-------------------+------------+
| 1           | How are you?      | How        |
| 4           | Hi, How are you?  | Hi, How    |
+-------------+-------------------+------------+

或如果我"Your name is?",它将显示如下结果:

+-------------+-------------------+------------+
| question_id | question          | word       |
+-------------+-------------------+------------+
| 2           | What's your name? | What, name |
+-------------+-------------------+------------+

4 个答案:

答案 0 :(得分:1)

你可以这样使用正则表达式

select * from my_table where question REGEXP 'How|are|you|';

答案 1 :(得分:0)

试试这个:

SELECT * FROM tbl_question WHERE question LIKE '%How are you?%'

答案 2 :(得分:0)

SELECT * FROM tbl_question WHERE word LIKE'%你好吗?%'

通过这个,你的数据库将尝试“回复”所有与句子完全一致的数据你好吗?正如我在单词中看到的那样,你只有特定的词语。

我创建了你的表并将数据插入其中并使用了查询

 SELECT 
       question FROM Custom WHERE word LIKE '%What%'

所以它给了我第二个问题。

如果可以,请向我解释一下您想要展示的内容。

答案 3 :(得分:0)

您输错了列名。请用问题替换它。SELECT * FROM tbl_question WHERE question LIKE %How are you%