gpt4 book ai didi

php - 在 php 中从字符串中搜索数字

转载 作者:行者123 更新时间:2023-11-29 05:04:25 25 4
gpt4 key购买 nike

我在从字符串中搜索数字时遇到问题,这很简单但我无法解决,我有 GALLERY 表

id | gallery_name | standard
____________________________
1 | aaa | 1,2
2 | bbb | 2
3 | ccc | 1,6, 12

我想找到有 2 个标准的画廊。为此,我运行以下查询

select * from galley where standard IN('%2%');

输出:它返回包含 2 个标准的前两行,还返回不包含 2 但包含 12 的 3 行

请帮我解决这个问题

谢谢

最佳答案

您可以使用 FIND_IN_SET()LIKE

select * from galley FIND_IN_SET('2',standard);

select * from galley 
where standard LIKE '%,2' OR standard LIKE '2,%' OR standard LIKE '%,2,%';

关于php - 在 php 中从字符串中搜索数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51321684/

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