我有一个班级表,里面的记录为
   
    id     className
  ---------------------------------
    1     07生物工程1班
     2     07生物工程1班
     3     07生物2班
     4     06生物1班
   我想实现个查询,就是查询className中包含"生物"的记录,但是我又只想要"07生物2班"和"06生物1班"这样的记录。
   请问怎么解决。谢谢

解决方案 »

  1.   

    SELECT *
    FROM tb_name
    WHERE className IN('07生物2班','06生物1班')
      

  2.   

    select * from tb where patindex('%07生物2班%',className)>0 or patindex('%06生物1班%',className)>0
      

  3.   

    select * from tb where classname = '07生物2班' or classname = '06生物1班'
      

  4.   

    SELECT *
    FROM tb_name
    WHERE className like '07生物%2班' or className like '06生物%1班'
      

  5.   


    declare @tb table(id int,    className varchar(50))
    insert @tb
    select     1,   '07生物工程1班' union all
    select     2,   '07生物工程1班' union all
    select     3,   '07生物2班' union all
    select     4,   '06生物1班' select * from @tb where patindex('%0[1-9]生物[1-9]班%',className)>0
    /*
    id          className                                          
    ----------- -------------------------------------------------- 
    3           07生物2班
    4           06生物1班
    */
      

  6.   


    declare @tb table(id int identity(1,1),className varchar(100))
    insert into @tb select '07生物工程1班'
    union all select '07生物工程2班' 
    union all select '07生物2班'
    union all select '06生物1班' 
    union all select '05生物3班' select * from @tb where patindex('%生物%',className)>0 and patindex('%生物工程%',className)=0
      

  7.   

    select * from tb where patindex('%0[1-9]生物[1-9]班%',classname)>0