如果只用sql语句是可以行的吗?
巴扎黑2017-04-17 14:41:22
select * from table where substring_index(field, ',', 1) = '10'
截取第一个逗号前面的部分
高洛峰2017-04-17 14:41:22
I don’t quite understand your question. According to my understanding, it is not simply select * from test where id = 10.
迷茫2017-04-17 14:41:22
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.
天蓬老师2017-04-17 14:41:22
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
天蓬老师2017-04-17 14:41:22
For reference: select * from test where concat(',', column, ',') like "%,10,%"