Data are as follows:
id col
1 a,b,d
2 a,b,c
My query conditions:
col=(a,b) requires finding two rows with IDs 1 and 2
col=(a,d) Find the row with id 1
col=(a,c) Find the row with id 2
col=(a) Find two rows with IDs 1 and 2
Could you please tell me if you have any methods?
大家讲道理2017-05-18 10:48:37
Take the first one as an example.
select * from tablename where find_in_set('a', col)>0 and find_in_set('b', col)>0;
阿神2017-05-18 10:48:37
1.SELECT * FROM test_findisset where find_in_set('a',col) and find_in_set('a',col) and find_in_set('b',col)
2.SELECT * FROM test_findisset where find_in_set('a',col) and find_in_set('a',col) and find_in_set('d',col)
3.SELECT * FROM test_findisset where find_in_set('a',col) and find_in_set('a',col) and find_in_set('c',col)
4.SELECT * FROM test_findisset where find_in_set('a',col) and find_in_set('a',col)