我认为您的问题没有任何直接的解决方案,但我已经做了一些工作,可能对您有用....
create table #table(id int,c varchar(2))
insert into #table values('1','a')
insert into #table values('1','a')
insert into #table values('2','b')
insert into #table values('2','b')
insert into #table values('3','c')
insert into #table values('3','c')
insert into #table values('4','d')
insert into #table values('5','d')
declare @table table(uid int,id int ,c varchar(2));
with tbl as (
select ROW_NUMBER() OVER(ORDER BY id DESC) AS uid ,id,c from #table
)
insert into @table select * from tbl
declare @tmpid int,@tmpuid int,@cnt int
declare tmpc cursor
for select uid,id from @table;
open tmpc
fetch next from tmpc
into @tmpuid,@tmpid
while @@FETCH_STATUS = 0
BEGIN
set @cnt = (select COUNT(id) from @table where id = @tmpid)
IF (@cnt > 1)
BEGIN
delete from @table where uid = @tmpuid
END
fetch next from tmpc
into @tmpuid,@tmpid
END
CLOSE tmpc;
DEALLOCATE tmpc;
select * from @table
drop table #table