本文介绍了mysql:如何选择内爆数组值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我有一列通过,
存储内爆数组值,如何在以下条件下选择数组值:
So I have a column that store imploded array values via ,
, how can I select array value with the following condition:
如果列存储的值如下:
+-----+------------------------------------------------------------+
| row | column |
+-----+------------------------------------------------------------+
| 1 | lorem ipsum,lorem ipsum dolor,lorem ipsum dolor sit amet |
| -- | -- |
| 2 | consectetuer adipiscing,lorem ipsum amet,lorem ipsum dolor |
| -- | -- |
| 3 | lorem ipsum,consectetuer adipiscing,lorem ipsum dolor |
+-----+------------------------------------------------------------+
我想选择具有 lorem ipsum 值的行,我知道我们可以使用 Like
,但是如果使用 like
,它也会选择 lorem ipsum dolor 或 lorem ipsum amet !
我尝试执行以下查询:
I want to select the rows that has lorem ipsum value, I know we can use Like
but if use like
, it select lorem ipsum dolor or lorem ipsum amet too!I try following query:
select * from table where column like '%lorem ipsum%'
# my expected rows :1,3
# query result :1,2,3
推荐答案
如果该值以逗号分隔(而不是逗号+空格分隔),则可以使用 FIND_IN_SET
:
If the value is comma-separated (and not comma+space separated), you can use FIND_IN_SET
:
SELECT * FROM `table` WHERE FIND_IN_SET('lorem ipsum', `column`);
这篇关于mysql:如何选择内爆数组值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!