mysql SELECT WHERE 字符串包含字符 [英] mysql SELECT WHERE string contains characters
本文介绍了mysql SELECT WHERE 字符串包含字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表字段 events
可以包含:
- 只有一个数字序列,例如:
45
- 或由符号
|
划分的数字序列,例如55|65|76
- Only a sequence of number, for example:
45
- or a sequence of number divided by the symbol
|
, for example55|65|76
我想我必须使用 LIKE
,但我不知道如何使用.你能帮我吗?
I think i have to use LIKE
, but i don't know how. Can you help me?
谢谢
推荐答案
我建议使用 CONCAT
在您的字段前后添加管道 |
,然后使用LIKE
搜索.像这样:
I would recommend using CONCAT
to add a pipe |
before and after your field, and then using a LIKE
search. Something like this:
SELECT *
FROM YourTable
WHERE concat('|',field,'|') like '%|45|%'
- SQL 小提琴演示
但是,我强烈建议您尝试规范化您的数据.考虑将这些存储在单独的行中,这将使搜索/维护更容易.
However, I highly recommend trying to normalize your data. Considering storing these in separate rows which would make searching/maintaining much easier.
这篇关于mysql SELECT WHERE 字符串包含字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文