我有等重复记录表 现在我只想要一个记录来自重复记录,其最新创建日期为我该怎么做?
答案 0 :(得分:3)
使用row_number()
:
select EnquiryId, Name, . . .
from (select t.*,
row_number() over (partition by enquiryID order by CreatedDate desc) as seqnum
from table t
) t
where seqnum = 1;
答案 1 :(得分:3)
使用ROW_NUMBER函数标记CreatedDate排序的重复记录,如下所示:
;with CTE AS (
select *, row_NUMBER() over(
partition by EnquiryID -- add columns on which you want to identify duplicates
ORDER BY CreatedDate DESC) as rn
FROM TABLE
)
select * from CTE
where rn = 1