在數據處理中,經常會遇到類似這樣的情況:數據庫中存在多條記錄,其中某些字段值相同,其他字段值不同.實際的業務需要針對這樣的情況,只保留一條數據,其他數據刪除.如何做到呢?在sql中有top關鍵字相對容易做到,但是在oracle中不支持top關鍵字,如果實現同樣的效果就會小費周折.具體實現方法如下舉例:
假如現在有表Test,其中記錄
select t1.*,rowid from test t1 where rowid in (select rowid from test t2 where t1.id=t2.id and t1.time=t2.time and rownum=1 );
或者