理論上相同數據個別字段值不同重復問題:
1.某字段重復,其他字段值不同時,按重復字段分組只取一條的sql語句
(eg:相同的數據某個字段值有差別導致存儲兩條或多條無意義重復數據的情況)
select s.* from (
select a.*, row_number() over (partition by [重復字段] order
by [不同字段]) as group_idx
from table_name a ) s
where s.group_idx= 1
2.某字段重復,其他字段不同,取重復字段值並去重sql語句(第二句復制過來的,未測試)
(1)select distinct a.id from a
(2)select id from a
where a.num = 1
group by id
having on count(id) > 1
===================刪除重復數據保留一條==================================
3、查找表中多余的重復記錄(多個字段)
select * from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
4、刪除表中多余的重復記錄(多個字段),只留有rowid最小的記錄
delete from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
---------------------
原文:https://blog.csdn.net/q571947988/article/details/79957906