数据表 emp
id   name   content
1      a     1,2,12,122,65
2      b     2,12,112,65
3      c     3,12,2
4      d     4,5,3
...   ......  ......
想要得到的结果
查询出含有"2"的记录
要么2在中间,则显示为",2,",要么2在最前面,"2,"或最后面",2"的记录
模糊查询或者有相关函数解决则更好,MYSQL的数据库
等待高人解决

解决方案 »

  1.   

    select * from emp where FIND_IN_SET('2',content);
      

  2.   

    select * from emp where if(FIND_IN_SET('2',content)>0,0,1);
    or
    select * from emp where if(instr(concat(',',content,','),',2,')>0,0,1);
      

  3.   

    我也来一条:
    select *,if(find_in_set(2,content)=1,"2,",if(find_in_set(2,content)>1 and find_in_set(2,content)<length(content),",2,", if(find_in_set(2,content)=length(content),",2",null))) as two from emp