删除表中所有记录只留下第一条,按照rownum排他,使用rowid删除

先生成表中的rownum然后删除rownum!=1的记录

 delete from emp where rowid in 
 (
 select id  from
 (
 select e.rowid id,rownum r from emp e where ename='TOM' and rownum <=(select count(*) from emp e where ename='TOM')
 ) 
 where r != 1
 )

猜你喜欢

转载自blog.csdn.net/weixin_42209307/article/details/81074726