一个MySql查询问题

数据如下:

id col
1 a,b,d
2 a,b,c

我的查询条件:

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

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

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

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

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

阅读 1.7k
2 个回答

以第一个为例。

select * from tablename where find_in_set('a', col)>0 and find_in_set('b', col)>0;

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)

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题