Code
create table Table1
(
id int identity(1,1) primary key,
col1 char(5),
col2 datetime,
col3 int
)
--筛选出重复数据(ID不同,其它列都相同)
with a as
(
select ROW_NUMBER() over(order by id desc) as rownumber,Table1.*
from Table1
),
b as
(
select min(rownumber) as minRow from a
group by col1,col2,col3
)
select id,a.*,b.minRow
from a left outer join b on a.rownumber = b.minRow
where b.minRow is null
create table Table1
(
id int identity(1,1) primary key,
col1 char(5),
col2 datetime,
col3 int
)
--筛选出重复数据(ID不同,其它列都相同)
with a as
(
select ROW_NUMBER() over(order by id desc) as rownumber,Table1.*
from Table1
),
b as
(
select min(rownumber) as minRow from a
group by col1,col2,col3
)
select id,a.*,b.minRow
from a left outer join b on a.rownumber = b.minRow
where b.minRow is null