描述:
数据myTable ,其中包含字段testA,testB表中的数据如下:
testA    testB
  a        b
  b        a
  c        d
  d        c现在想编写一个SQL 语句过滤上面数据表,剩下下面的信息:
testA    testB
  a        b
  c        d请问各位大侠SQL 语句怎么写?

解决方案 »

  1.   

    你需要保留的a和b;或者是c和d之间是否存在大小关系.不考虑需要保留的数据中的testA和testB之间满足大小关系
    delete from myTable a where exists(
    select 1 from myTable b where a.testA = b.testB and a.testB = b.testA and a.rowid > b.rowid ) ./*只判断是否存在对称重复的记录,删除rowid较大的记录*/假设保留的均为testA<testB的记录的话,可以试下下面的语句.
    delete from myTable a where exists(
    select 1 from myTable b where a.testA = b.testB and a.testB = b.testA and a.rowid <> b.rowid ) and testA > testB. 
    /*判断存在对称重复的记录,对testA大于testB的记录进行删除*/