Chinaunix首页 | 论坛 | 博客
  • 博客访问: 158747
  • 博文数量: 27
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 701
  • 用 户 组: 普通用户
  • 注册时间: 2013-02-22 17:14
个人简介

诚信打天下

文章分类

全部博文(27)

文章存档

2013年(27)

我的朋友

分类: SQLServer

2013-02-22 17:55:47

在oracle中 可以直接使用in 来 匹配,sql server 中不可以使用in关键字多字段匹配,所以选择使用 and
连接。下面用Min()函数保留组前面一条记录,如果保留最后一条记录用Max()函数。

select * from test2 
where (t1 in (select 
t1 from test2 group by t1 having count(*) >1 )) and (t2 in 
(select t2 from test2 group by t2 having count(*) >1 
)) 
and tid not in (select min(tid) from test2 
group by t1 having count(*) >1 ) 
and tid not in (select 
min(tid) from test2 group by t2 having count(*) >1 ) 


在oracle中删除多余的重复项

select * from test2 

where (t1,t2) in (select t1,t2 from test2 group by 
t1,t2 having(count(*)>1 )) 



阅读(1706) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~