设为首页 加入收藏

TOP

sql如何删除部分字段重复的数据
2014-11-24 02:49:57 来源: 作者: 【 】 浏览:4
Tags:sql 如何 删除 部分 重复 数据

思路:找到最大的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字段中的换行符,回车符 下一篇sql截取字段最后以特定字符隔开的..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·用 Python 进行数据 (2025-12-25 15:49:09)
·如何学习Python数据 (2025-12-25 15:49:07)
·利用Python进行数据 (2025-12-25 15:49:04)
·Java 学习线路图是怎 (2025-12-25 15:19:15)
·关于 Java 学习,有 (2025-12-25 15:19:12)