2

考虑以下消息:

id  message
------------------------------------------------------------
1   $AA is the only way to go!
2   This is my $AA. There are many like it.
3   But this is my $AA.
4   My$AA is my swag.
5   For lack of imagination a message with $AA in the middle.
6   Another message with at the end: $AA

我想用 $AA 过滤所有消息:

  • $AA 可以在消息的开头(所以:它后面只有一个空格)
  • $AA 可以在消息的末尾(所以:它之前只有一个空格)
  • $AA 可以在消息中的任何其他位置(由空格包围)
  • $AA 之前和/或之后可以有标点符号:$AA。$AA 或 ($AA)
  • 但不是任何其他字符(字母和数字)

我通常会使用查询,例如

SELECT * FROM messages WHERE message LIKE '%$AA%'

但随后消息 4 也被返回。如何使查询不返回消息 4?

4

1 回答 1

1

像这样在查询中添加一个空格太容易了-

SELECT * FROM table_name WHERE messages LIKE '% $AA%'

这不会覆盖第一行

用这个:

SELECT * FROM table_name WHERE messages LIKE '% $AA%' or messages like '$AA%'
于 2012-04-19T14:04:01.287 回答