sql若何删除部份字段反复的数据[MSSQL防范]
本文“sql若何删除部份字段反复的数据[MSSQL防范]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
思绪:找到最大的rowid便可.
Sql代码
alter proc getNotDupData
as
--clear temp table
delete ODS.dbo.Agent
delete from stage.dbo.tmpDup
delete from stage.dbo.tmpRowNo
delete from stage.dbo.tmpMaxRowNo
--create dup table
insert into stage.dbo.tmpDup
select distinct AgentLogin,AgentSurName,AgentGivenName from stage.dbo.dAgentPerformanceStat
where AgentSurname is not null and agentlogin like '3%' order by AgentLogin
--add rowNo
insert into tmpRowNo
select *,ROW_NUMBER()over(order by AgentLogin) as rowno from tmpDup
--get max rowno
insert into stage.dbo.tmpMaxRowNo
select max(rowno) as 'rowno' from stage.dbo.tmpRowNo group by AgentLogin having count(*)>1
--remove max rowno
delete from stage.dbo.tmpRowNo where rowno in (select * from stage.dbo.tmpMaxRowNo)
--insert into ods
insert into ODS.dbo.Agent select AgentLogin,AgentSurName,AgentGivenName from stage.dbo.tmpRowNo
作者 wandejun1012
以上是“sql若何删除部份字段反复的数据[MSSQL防范]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |