mysql - 如果一张表里有这么两行数据,数据中某一字段值为 10,100跟 100,99 时,如何找到值里有10的那一行?
巴扎黑
巴扎黑 2017-04-17 14:39:22
0
5
832

如果只用sql语句是可以行的吗?

巴扎黑
巴扎黑

모든 응답(5)
巴扎黑
select * from table where substring_index(field, ',', 1) = '10'
截取第一个逗号前面的部分
小葫芦

不太明白你的问题,按照我的理解不就是简单的select * from test where id = 10。

迷茫

使用模糊匹配:select * from test where column like "%10%"
PS:感觉这样的需求有些奇怪,是否数据库设计不合理。

Peter_Zhu

从题意上看,解决办法可以是
自定义函数,切分字段用的,然后再判断,
1.自定义函数,待补
2.查询语句
select * from table where 1=hasTen(column)

粗暴妥协一点的做法
select * from table where column like '10,%'
||
select * from table where column like '%,10,%'
||
select * from table where column like '%,10'

如果能够保证字段一定是a,b的形式或许会好解决一点

Peter_Zhu

参考一下:select * from test where concat(',', column, ',') like "%,10,%"

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!