gpt4 book ai didi

php - Mysql 正则表达式

转载 作者:行者123 更新时间:2023-12-01 00:23:41 25 4
gpt4 key购买 nike

我有一个关于正则表达式的查询。我设计了一个包含三列的表,其中一列包含用逗号分隔的成员 ID。我正在向您展示我的表结构。请按照

send_id    member_id

1 1211,23,34
2 1,23

我只想选择包含 member_id 为 1 的 send_id 2 数据。

这是我正在使用的查询

SELECT * FROM table WHERE column REGEXP '^[1]+$';

但是这个查询给了我两行。请帮助我。

问候

拉胡尔

最佳答案

永远不要在一列中存储单独的值

像这样规范化你的结构

send_id    member_id1          12111          231          342          12          23

If you still want your regex, then it will be

SELECT * FROM t WHERE column REGEXP '(^|[^0-9])1([^0-9]|$)'

关于php - Mysql 正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19225356/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com