例如数据库中有如下记录
A 1
A 2
A 3
B 1
B 2
C 1
C 3
我想查询只包含1或者1和3的记录,请问怎么写呢

解决方案 »

  1.   

    字母跟数字是分别2个字段吗?
    如果是的话。select * from tablename t where t.数字=1 and  t.数字=3
      

  2.   

       
       
       假设 你的2个字段的名字分别是A 与 B
       select * from table where B=1 or B=3
       
      

  3.   

    select * from tablename t where t.数字=1  只包含1
    select * from tablename t where t.数字 in(1,3) 1和3
      

  4.   

    lz的意思是 以a分组  b组只能出现1或者1和3?假设表名tb1,2列为col1,col2select * from 
    (select col1,wm_concat(col2) col2
    from tb1
    group by col2)
    where col2 in ('1','1,3')
      

  5.   

    如果wm_concat得到的是('3,1')呢!不是漏掉了许多记录。
      

  6.   


     嗯 貌似有可能  那改成where col2 in ('1','1,3','3,1')应该可以了
      
     
      

  7.   

    兄弟,看一下!下面sql是否满足你的需求:   with t2 as(
      select 'a' a,1 b from dual
      union 
      select 'a',2 from dual
      union
      select 'a',3 from dual
       union
      select 'b',1 from dual
       union
      select 'b',2 from dual
       union
      select 'c',1 from dual
      union
      select 'c',3 from dual
    )
    select * from t2 t where (t.b=1 or t.b in(1,3));