博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SQL Server2005中删除重复行
阅读量:3599 次
发布时间:2019-05-20

本文共 1339 字,大约阅读时间需要 4 分钟。

以前写的东西,可以看看思路

 

/*
删除表中重复行的方法
*/
if
 
exists
(
select
 
1
 
from
 sys.tables 
where
 name
=
'
t_dup
'
)
    
drop
 
table
 t_dup
go
create
 
table
 t_dup(id 
int
,age 
int
,name 
varchar
(
32
))
insert
 
into
 t_dup
select
 
1
,
1
,
'
a
'
union
 
all
 
select
 
1
,
1
,
'
a
'
union
 
all
 
select
 
1
,
1
,
'
a
'
union
 
all
 
select
 
1
,
2
,
'
a
'
union
 
all
 
select
 
1
,
2
,
'
e
'
union
 
all
 
select
 
2
,
3
,
'
b
'
union
 
all
 
select
 
3
,
3
,
'
d
'
go
select
 
*
 
from
 t_dup
go
with
 t_all 
as
    (
select
 id,age,name,row_number() 
over
(
order
 
by
 id) 
[
num
]
     
from
 t_dup),
    t_max 
as
    (
select
 id,age,name,
max
(num) num
     
from
 t_all
     
group
 
by
 id,age,name)
select
 id,name,age 
from
 t_all a 
where
 
exists
(
select
 
1
 
from
 t_max 
where
 num
=
a.num)
 
<script type="text/javascript">document.write("
");</script>
<script type="text/javascript">LoadFeedbackCount();</script> <script language="javascript" type="text/javascript"> ad_width=468; ad_height=60; adcss=2; unionuser=19; tags=''; ad_type='j'; count=2; </script> <script type="text/javascript" src="http://tagegg.csdn.net/showads.js" language="javascript"></script> <script src="http://tagegg.csdn.net/b.aspx?action=displayad&unionuser=19&unionurl=http%3A%2F%2Fblog.csdn.net%2Fwhbo%2Farchive%2F2008%2F05%2F07%2F2412445.aspx&adcss=2&ad_type=j&width=468&height=60&ad_color=&ad_color_border=&count=2" language="JavaScript1.1" type="text/javascript"></script>
你可能感兴趣的文章
UnsupportedClassVersionError-异常解决
查看>>
Mysql (InnoDB&MyISAM )-如何在两种存储引擎中进行选择?
查看>>
SpringAop两种代理模式-源码分析
查看>>
IDEA-自定义常用代码块
查看>>
JAVA多线程-JUC-8锁
查看>>
Vue-实现对象拷贝
查看>>
export 命令导出变量
查看>>
JAVA-快速接入第三方应用登录(QQ、微信、微博)
查看>>
解决Mysql-无法批量更新的问题
查看>>
Springboot-logback配色方案
查看>>
面试题-给定一个“flatten”Dictionary对象,根据键转换成嵌套字典对象
查看>>
用cookies实现主题背景颜色切换,保存选择的颜色
查看>>
用 node.js 开启一个 http服务,返回文件或信息
查看>>
【git】warning: adding embedded git repository
查看>>
git warning: LF will be replaced by CRLF in 解决办法
查看>>
python文件处理
查看>>
CentOS7制作本地yum源
查看>>
参考花书《深度学习》实现一个简易版PCA
查看>>
CSDN Markdown编辑器——文本颜色、大小、字体设计
查看>>
Looper源码分析
查看>>