select a.* 
from table_name  a,
 (select order_code,count(*) from table_name 
     group by order_code 
     having count(*)=2) b
where a.order_code=b.order_code

解决方案 »

  1.   

    select order_code from MyDB group by order_code having count(order_code) > 2
      

  2.   

    a是这个表的别名,b是从这个表中查出来的部分数据集合的别名
    是把每一个符合条件的记录都找出来吗
    SQL> select * from test;CO COL2
    -- ----
    1  aa
    2  aa
    3  bb
    4  cc
    5  cc
    6  dd已选择6行。SQL> select * from test where col2 in
      2  (select col2 from test group by col2 having count(col2)=2);CO COL2
    -- ----
    1  aa
    2  aa
    4  cc
    5  cc
      

  3.   

    select * from test where id in (select id from test group by id having count(1)=2