有一table id    userid     username
1         a                qqq
 1         b               dfdd
2          c               dsds
3          d               sdsd
4           e              dfdf
5           f                ggjh
6          g               ghjj
2           h              kgte现要求得到id(地到的id必须是有两个或两以上相同的)即:
id      userid   username
1         a             qqq
1         b              dfdd
2         c              dsds
2         h              kgte
请问该怎么实现

解决方案 »

  1.   

    select * 
    from tablename 
    where id in (
                 select id 
                 from tablename 
                 group by id
                 having count(*) > 1
                 )
      

  2.   

    drop table t;
    create table t
     ( id number,
       name number);
    insert into t
    select 1,536 from dual
    union all
    select 1,258 from dual
    union all
    select 2,256 from dual
    union all
    select 2,243 from dual
    union all 
    select 3,189 from dual;select * 
    from t
    where id in (select id
         from
         (
              select id,name,
                row_number() over (partition   by   id   order   by   id   desc) r
             from t
         )
         where r=2)
      

  3.   

    select id,userid,username,
     from table_name group by id having count(id)>=2;
      

  4.   

    不好意思,写错了!!
    select   *   
    from   tablename   
    where   id   in ( select   id   from   tablename   group   by   id  having  count(id)>= 2 )
      

  5.   

    select * from t t1 where exists(select 1 from t t2 where t1.id=t2.id and t1.rowid<>t2.rowid)
      

  6.   

    select * from tablename 
    where exists(select 1 from tablename group by id having count(*)>1)
      

  7.   

    ruihuahan正解,应该是最好的解决方法了。
    这个问题简单。。