日期:2014-05-18 浏览次数:20448 次
select [号码],[内容] from [表] group by [号码],[内容] having count(1)>1
------解决方案--------------------
if OBJECT_ID('表a') is not null drop table [表a] go create table [表a](groupnum int,B int) INSERT INTO [表a] VALUES(1,11) INSERT INTO [表a] VALUES(1,11) INSERT INTO [表a] VALUES(1,10) INSERT INTO [表a] VALUES(2,11) INSERT INTO [表a] VALUES(2,20) INSERT INTO [表a] VALUES(2,20) INSERT INTO [表a] VALUES(2,11) INSERT INTO [表a] VALUES(2,15) INSERT INTO [表a] VALUES(3,23) INSERT INTO [表a] VALUES(3,23) INSERT INTO [表a] VALUES(3,15) INSERT INTO [表a] VALUES(3,6) INSERT INTO [表a] VALUES(3,6) INSERT INTO [表a] VALUES(3,6) ;with cte as ( select * ,rn=ROW_NUMBER()over(partition by groupnum,B order by groupnum) from 表a ) select * from cte where rn<>1 groupnum B rn ----------- ----------- -------------------- 1 11 2 2 11 2 2 20 2 3 6 2 3 6 3 3 23 2 (6 行受影响)
------解决方案--------------------
if OBJECT_ID('表a') is not null drop table [表a] go create table [表a](号码 int,内容 varchar(50),时间 datetime) INSERT INTO [表a] VALUES(23434,'好好学习','2011-01-01 08:03:10') INSERT INTO [表a] VALUES(23434,'好好学习','2011-02-01 08:03:10') INSERT INTO [表a] VALUES(6777,'天天向上','2011-03-01 08:03:10') INSERT INTO [表a] VALUES(23434,'好好学习1','2011-01-01 08:03:10') ;with cte as ( select * ,rn=ROW_NUMBER()over(partition by 号码,内容 order by 号码) from 表a ) select * from cte where rn=1 号码 内容 时间 ----------- -------------------------------------------------- ----------------------- 23434 好好学习 2011-02-01 08:03:10.000 (1 行受影响)
------解决方案--------------------