oralce中,表有两个字段 fld1  fld2,
fld1    fld2
a       b
b a若是如上面那样有出现两个字段值互换的情况下,如何判断两条记录是相同的,取出记录数为1来比如  如下情况
fld1    fld2
a       b
b a
a       c
取出记录数是2fld1    fld2
a       b
b a
a       c
c       a
取出记录数是2

解决方案 »

  1.   

    select * from T where not exists(select * from T t1 where t1.fld1=T.fld2 t1.fld2=T.fld1)unionselect * from T where  exists(select * from T t1 where t1.fld1=T.fld2 t1.fld2=T.fld1)
      
    *****************************************************************************
    签名档: http://feiyun0112.cnblogs.com/
      

  2.   

    在C#中,可以重写IEqualityComparer<T>接口来实现:
    http://msdn.microsoft.com/en-us/library/bb338049.aspx
     public bool Equals(Product x, Product y)
        {        //Check whether the compared objects reference the same data. 
            if (Object.ReferenceEquals(x, y)) return true;        //Check whether any of the compared objects is null. 
            if (Object.ReferenceEquals(x, null) || Object.ReferenceEquals(y, null))
                return false;        //Check whether the products' properties are equal. 
            return (x.Code == y.Code && x.Name == y.Name)||(x.Code == y.Name && x.Name == y.Code);
        }
      

  3.   


    没怎么看明白意思,平时都是用的SQL2000,对ORACLE不怎么熟悉,复制你的语句到PLSQL里面,在 where not exists前提示SQL命令未正确结束。能再详细点吗?我是菜鸟,谢谢了。
      

  4.   

    谢谢 feiyun0112 非常有用