select s.tid,s.rowid from test12 s,test12 t where s.rowid>t.rowid and t.tid=s.tid;
21 AAAMP+AAEAAAAC0AAD
23 AAAMP+AAEAAAAC0AAF
select s.tid,s.rowid from test12 s,test12 t where s.rowid<t.rowid and t.tid=s.tid;
21 AAAMP+AAEAAAAC0AAC
23 AAAMP+AAEAAAAC0AAE
删除方法一:成功!
delete test12 t where t.rowid not in (select min(s.rowid) from test12 s where t.tid=s.tid group by s.tid);----如果是保留最大的唯一行,换max即可。
TID TNAME TTIME SSEX ROWID
11 12 AAAMP+AAEAAAAC0AAA
111 1a2 AAAMP+AAEAAAAC0AAB
21 2121 2012-11-13 15:30:45 AAAMP+AAEAAAAC0AAC
23 2121 2012-11-13 15:41:31 女 AAAMP+AAEAAAAC0AAE
删除方法二:失败!
delete test12 t where t.rowid in (select s.rowid from test12 s where s.tid=t.tid and s.rowid>t.rowid);
解:
由于这个例子的特殊性,所以select s.tid,s.rowid from test12 s,test12 t where s.rowid>t.rowid and t.tid=s.tid;
和
select s.tid,s.rowid from test12 s,test12 t where s.rowid<t.rowid and t.tid=s.tid;可以查询出来正确的结果。
测试:
insert into test12 values(23,'fsf',sysdate,'F');
insert into test12 values(23,'fsf',sysdate,'M');
补充:如果要指定删除重复(tid)行为4(N)行以上的,保留最小的行,其他的删除。
则在where后增加rowid not in (select min(rowid) from test12 group by tid having count(*) >4) and tid in (select tid from test12 group by tid having count(*) >4);这种方法更加灵活,可以实现的功能更多。