现有表:A1
    a    b
    1    2
    1    3
    1    4
    2    1
    2    2我想从A1表中,以a字段分组,比如前三条数据位一组,然后b字段中既有2,又有3的纪录
也就是说,以这个例子为例,检索出 1,2;1,3

解决方案 »

  1.   

    select a,2  
    from A1 
    where b=2 or b=3
    group by a
    having count(*)>1
    union
    select a,3  
    from A1 
    where b=2 or b=3
    group by a
    having count(*)>1
      

  2.   

    select  distinct *
    from  A1
    where (b=2 or b=3 ) and a in (select a
                                                        from A1
                                                        where b=2 or b=3
                                                         group by a
                                                         having count(*)>1)