思路:找到最大的rowid即可。
?
alter proc getNotDupDataas--clear temp tabledelete ODS.dbo.Agentdelete from stage.dbo.tmpDupdelete from stage.dbo.tmpRowNodelete from stage.dbo.tmpMaxRowNo--create dup tableinsert into stage.dbo.tmpDupselect distinct AgentLogin,AgentSurName,AgentGivenName from stage.dbo.dAgentPerformanceStatwhere AgentSurname is not null and agentlogin like '3%' order by AgentLogin--add rowNoinsert into tmpRowNoselect *,ROW_NUMBER()over(order by AgentLogin) as rowno from tmpDup --get max rownoinsert into stage.dbo.tmpMaxRowNoselect max(rowno) as 'rowno' from stage.dbo.tmpRowNo group by AgentLogin having count(*)>1这句话是所有去重的精髓啊,哈哈。--remove max rownodelete from stage.dbo.tmpRowNo where rowno in (select * from stage.dbo.tmpMaxRowNo)--insert into odsinsert into ODS.dbo.Agent select AgentLogin,AgentSurName,AgentGivenName from stage.dbo.tmpRowNo
?
?
?
附上删除另外一个重复的例子,和上面的有点类似,但是用在不同的项目里的,放在这里加深一下印象:
?
select max(id) from T_CUST_CUSTINFO_12 where a627='yc201204-5' group by a606 having count(*)>1?
?
?
?
?
?
?