我有一张带有唯一id但有重复行信息的表格。
我可以使用以下查询找到具有重复信息的行。
SELECT
PersonAliasId, StartDateTime, GroupId, COUNT(*) as Count
FROM
Attendance
GROUP BY
PersonAliasId, StartDateTime, GroupId
HAVING
COUNT(*) > 1
我可以使用此查询手动删除行并保留所需的1。
Delete
From Attendance
Where Id IN(SELECT
Id
FROM
Attendance
Where PersonAliasId = 15
and StartDateTime = '9/24/2017'
and GroupId = 1429
Order By ModifiedDateTIme Desc
Offset 1 Rows)
我对SQL不够熟悉,无法想出如何使用第一个查询中的行来删除重复项,只留下最近的。第一个查询返回了超过3481条记录,手动逐一处理非常耗时。
我该如何像第一个查询一样找到重复行,并删除除最近的之外的所有内容?