问个SQL查寻问题。删出重复项问题,要查寻语句。
时间:2011-11-16
来源:互联网
a列 B列 c列
1 2 3
2 2 5
3 2 6
1 2 6
要求:
删除这份表中A列为重复的行。就是把A列中为“1”的行删出,为“1”的行随便保留一行即可。
想要的结果为:
a列 B列 c列
1 2 3
2 2 5
3 2 6
或:
2 2 5
3 2 6
1 2 6
谢谢
1 2 3
2 2 5
3 2 6
1 2 6
要求:
删除这份表中A列为重复的行。就是把A列中为“1”的行删出,为“1”的行随便保留一行即可。
想要的结果为:
a列 B列 c列
1 2 3
2 2 5
3 2 6
或:
2 2 5
3 2 6
1 2 6
谢谢
作者: sxssg 发布时间: 2011-11-16
SQL code
select * from tb a where not exists(select 1 from tb where a=a.a and c<a.c)
作者: qianjin036a 发布时间: 2011-11-16
select t.* from tb t where c = (select min(c) from tb where a = t.a)
select t.* from tb t where c = (select max(c) from tb where a = t.a)
select t.* from tb t where not exists (select 1 from tb where a = t.a and c < t.c)
select t.* from tb t where not exists (select 1 from tb where a = t.a and c > t.c)
select t.* from tb t where c = (select top 1 c from tb where a = t.a and order by c)
select t.* from tb t where c = (select top 1 c from tb where a = t.a and order by c desc)
select t.* from tb t where c = (select max(c) from tb where a = t.a)
select t.* from tb t where not exists (select 1 from tb where a = t.a and c < t.c)
select t.* from tb t where not exists (select 1 from tb where a = t.a and c > t.c)
select t.* from tb t where c = (select top 1 c from tb where a = t.a and order by c)
select t.* from tb t where c = (select top 1 c from tb where a = t.a and order by c desc)
作者: dawugui 发布时间: 2011-11-16
SQL code
delete a from table1 as a where exists(select 1 from table1 where a=a.a and c>a.c)
作者: roy_88 发布时间: 2011-11-16
SQL code
--> --> (Roy)生成測試數據 if not object_id('Tempdb..#T') is null drop table #T Go Create table #T([a] int,[B] int,[c] int) Insert #T select 1,2,3 union all select 2,2,5 union all select 3,2,6 union all select 1,2,6 Go delete a from (Select * ,row=row_number()over(partition by a order by newid())from #T)a where row>1 select * from #T
作者: roy_88 发布时间: 2011-11-16
保留A列相同的,任何一条记录可用以上方法
作者: roy_88 发布时间: 2011-11-16
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28