例子:
如有表test,test有四个字段:a,b,c,d.其中a为主关键字段.
对于b,c,d三个字段重复的记录, 只留下一条记录,其余的删除.
代码如下:
delete from test
where a in
(
select a
from (
select a,b,c,d
rank() over (partition by b,c,d order by a nulls last) tmp
from (
select a,b,c,d
from test
where a in
(select a,
from test
group by b,c,d
having count(*) > 1
)
)
)
where tmp >1
); |