数据库的表有4个字段
a1,a2,a3,a4
如何把表中a1,a2相等,但a4不相等的纪录找出来?

解决方案 »

  1.   

    1  select a,b,c,d from (
      2  select a,b,c,d,decode(a,b,decode(a,d,1,0),0) f from test)
      3* where f=1
    SQL> /         A          B          C          D
    ---------- ---------- ---------- ----------
             1          1          4          1SQL> select * from test;         A          B          C          D
    ---------- ---------- ---------- ----------
             1          1          3          2
             1          1          4          1
             1          2          4          1
      

  2.   

    select a1,a2,a3,a4 from (
      select a1,a2,a3,a4,decode(a1,a2,decode(a1,a4,0,1),0) b from test)
    where b=1;
      

  3.   

    select *
      from table1 a
     where exists (select 1
              from table1 b
             where a.a1 = b.a1
               and a.a2 = b.a2
               and a.rowid != b.rowid
               and a.a4 != b.a4)
      

  4.   

    select t1.*
    from table t1,table t2
    where t1.a1=t2.a1
    and t1.a2=t2.a2
    and t1.a4<>t2.a4
      

  5.   


    select a.a1,a.a2,a.a3,a.a4 from table a
             where (a.a1=a.a2
             and  a.a1<>a.a4)
             or   (a.a2<>a.a4 and a.a1=a.a2)