select a,b from test 
minus
select a,b from test t where exists(select 1 from test tt t.a||t.b=tt.a||tt.b);

解决方案 »

  1.   

    sorry!
    上面的那个不正确。
    SQL> select * from test;         A          B
    ---------- ----------
             1          2
             2          1
             1          3
             3          4
             4          3
             3          1已选择6行。已用时间:  00: 00: 00.50
    SQL> select a,b from test 
      2  minus
      3  select a,b from test t where a>b and 
      4  exists(select 1 from test tt where t.a||t.b=tt.b||tt.a);         A          B
    ---------- ----------
             1          2
             1          3
             3          4已用时间:  00: 00: 00.20
    SQL>
      

  2.   

    a,b都是数字可以这样
    select distinct decode(sign(a-b),1,b,a) g1,decode(sign(a-b),1,a,b) g2 from test
      

  3.   

    字符情况的测试:
    SQL> select * from test;A                    B
    -------------------- --------------------
    aa                   bb
    bb                   aa
    cc                   dd
    ee                   dd
    dd                   cc已用时间:  00: 00: 00.30
    SQL> select a,b from test 
      2  minus
      3  select a,b from test t where a>b and 
      4  exists(select 1 from test tt where t.a||t.b=tt.b||tt.a);A                    B
    -------------------- --------------------
    aa                   bb
    cc                   dd
    ee                   dd已用时间:  00: 00: 00.40
    SQL>
      

  4.   

    select distinct least(a,b), greatest(a,b) from t;
      

  5.   

    这样就可以了
    select distinct decode(sign(ASCII(a)-ASCII(b)),1,b,a) g1,decode(sign(ASCII(a)-ASCII(b)),1,a,b) g2 from test
      

  6.   

    bobfang(匆匆过客)正解
    忘了有least(), greatest()函数了:)