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

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

巴扎黑
巴扎黑

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

I don’t quite understand your question. According to my understanding, it is not simply select * from test where id = 10.

迷茫

Use fuzzy matching: select * from test where column like "%10%"
PS: I feel that such a requirement is a bit strange, maybe the database design is unreasonable.

Peter_Zhu

From the perspective of the question, the solution can be
Custom function, used to segment fields, and then judge,
1. Custom function, to be added
2. Query statement
select * from table where 1=hasTen(column)

A rough compromise
select * from table where column like '10,%'
||
select * from table where column like '%,10,%'
||
select * from table where column like '%,10'

It may be easier to solve if you can ensure that the fields must be in the form of a and b

Peter_Zhu

For reference: select * from test where concat(',', column, ',') like "%,10,%"

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!