有以下几行记录:
abcd
adec
ehakc
rtathc
ifdas
想找出所有同时包含"a"和"c"的记录,请问有什么办法可以实现,谢谢

解决方案 »

  1.   

    select * from tb where patindex('%[ac]%',col)>0
      

  2.   

    select * from tb where charindex('a',col)>0 and charindex('c',col)>0
      

  3.   

    like "*a*c*" or "*c*a*"
      

  4.   

    if object_id('tb') is not null drop table tb 
     go 
    create table tb([col] varchar(10))
    insert tb select 'abcd'
    union all select 'adec'
    union all select 'ehakc'
    union all select 'rtathc'
    union all select 'ifdas'
    go
    select * from tb where charindex('a',col)>0 and charindex('c',col)>0
    /*
    col
    ----------
    abcd
    adec
    ehakc
    rtathc(4 行受影响)
    */
      

  5.   


    select * from tb where col like '%a%c%' or col like '%c%a%'
      

  6.   


    select * from tb where charindex('a',col)>0 and charindex('c',col)>0
    or
    like "*a*c*" or "*c*a*"
      

  7.   

    SELECT * from 表 where 字段 like "%[a,c]%"
      

  8.   

    谢谢各位的帮助,如果记录为以下样子表:
    良好;一般;优秀;差;极差
    一般;差;极差
    良好;差;优秀
    一般;差
    良好;优秀
    良好;一般;优秀
    找出所有同时包"良好"和"优秀"的记录,除了LIKE之外,还有没有别的方法,另外,如果用LIKE在记录多的情况下会不会变慢,谢谢
      

  9.   

    select * from tb where charindex('a',col)>0 and charindex('c',col)>0
      

  10.   

    select * from tb where charindex('良好',col)>0 and charindex('优秀',col)>0