SELECT firstname, lastname, count(*) FROM people GROUPBY firstname, lastname HAVINGcount(*) >1;
using partition
1 2 3 4 5 6 7 8 9
SELECT*FROM (SELECT*, count(*) OVER (PARTITIONBY firstname, lastname ) AS count FROM people) tableWithCount WHERE tableWithCount.count >1;
Using not strict distinct
利用 not strict distinct DISTINCT ON 找到唯一的那些条,剩余的就是重复的,可以修改或删除
1 2 3 4 5 6 7 8 9
DELETEFROM people WHERE people.id NOTIN (SELECT id FROM ( SELECTDISTINCTON (firstname, lastname) * FROM people));
// more readable code WITHuniqueAS (SELECTDISTINCTON (firstname, lastname) *FROM people) DELETEFROM people WHERE people.id NOTIN (SELECT id FROMunique);