您的位置:首页技术文章
文章详情页

一个MySql查询问题

浏览:66日期:2022-06-13 10:46:40

问题描述

数据如下:

idcol1a,b,d 2a,b,c

我的查询条件:

col=(a,b) 要求查到id为1,2的两行

col=(a,d) 查到id为1的行

col=(a,c) 查到id为2的行

col=(a) 查到id为1,2的两行

请教下大家有没有什么方法呢?

问题解答

回答1:

以第一个为例。

select * from tablename where find_in_set(’a’, col)>0 and find_in_set(’b’, col)>0;回答2:

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)

相关文章: