表A,结构如下
id        group_id
1         1,2,3,4,5
2         45,33,31,69,12
3         4,6,3,77,45,13,16,109,112
5         6,12,66,77,88如何查出所有列中,出现字符3的

解决方案 »

  1.   

    select * from A where instr(group_id,3)
      

  2.   

    多谢。。MYSQL有自带函数就是爽啊··
      

  3.   

    还有locate 和find_in_set 都可以实现
      

  4.   

    mysql> use c1
    Database changed
    mysql> select * from a;
    +----+---------------------------+
    | id | Gruop_id                  |
    +----+---------------------------+
    |  1 | 1,2,3,4,5                 |
    |  2 | 45,33,31,69,12            |
    |  3 | 4,6,3,77,45,13,16,109,112 |
    |  4 | 6,12,66,77,88             |
    +----+---------------------------+
    4 rows in set (0.00 sec)
    mysql> select * from a where instr(LPAD(RPAD(Group_id,length(Group_id)+1,','),le
    ngth(Group_id)+2,','),',3,')<>0;
    +----+---------------------------+
    | id | Group_id                  |
    +----+---------------------------+
    |  1 | 1,2,3,4,5                 |
    |  3 | 4,6,3,77,45,13,16,109,112 |
    +----+---------------------------+
    2 rows in set (0.00 sec)mysql>
      

  5.   

    我发现真的要好好看看帮助文档了··也感谢 lxq19851204 兄
      

  6.   

    mr_mablevi
    哥们还在不?
    我这有2个查询条件的时候,查询出的数据不准确···