I have a table in MySQL with these data in it
我在MySQL中有一个包含这些数据的表
I want to get rows with "1" in column row1 by regex. How should I do that?
我想通过regex在列row1中获得带“1”的行。我该怎么做?
([^,]1/)
i use this regex but it only return the rows with "1" in first comma
我使用这个正则表达式,但它只返回第一个逗号中带有“1”的行
2 个解决方案
#1
4
You can use FIND_IN_SET() function of mysql
您可以使用mysql的FIND_IN_SET()函数
select * from my_table where FIND_IN_SET('1',row1) > 0
#2
2
Try:
尝试:
select *
from tbl
where row1 REGEXP '(^|,)1(,|$)'
(^|,)1(,|$)
means (either begenning
or ,
)1(either ,
or end
)
sql fiddle demo
(^ |,)1(,| $)表示(或者是,或者),1(或者,结束)sql小提琴演示
#1
4
You can use FIND_IN_SET() function of mysql
您可以使用mysql的FIND_IN_SET()函数
select * from my_table where FIND_IN_SET('1',row1) > 0
#2
2
Try:
尝试:
select *
from tbl
where row1 REGEXP '(^|,)1(,|$)'
(^|,)1(,|$)
means (either begenning
or ,
)1(either ,
or end
)
sql fiddle demo
(^ |,)1(,| $)表示(或者是,或者),1(或者,结束)sql小提琴演示