介紹三種方法:
1.建立組合索引
create index idx_name_id on table(name,id);
delete from table a
where exists(select null from table b
where b.name=a.name
and b.id>a.id);
2.建立單索引name,用rowid代替id
delete from table a
where exists(select null from table b
where b.name=a.name
and b.rowid>a.rowid);
3.通過分析函數,根據name分組生成序號,然後刪除序號大於1的數據
delete from table
where rowid in(select rid
from (select rowid as rid,
row_number() over(partition by name order by id) as seq
from table)
where seq>1);