我有一个有方法
感觉有点笨你可以看一下
我用我自己表试了一下没有问题
declare @id int
--建一个临时表
if object_id('Tempdb..#temp') is not null
begin
drop table #temp
end
else
begin
create table #temp
(
[用户ID] int ,
[更新日期] varchar(100),
[更新动作] varchar(200)
)
end
declare cursor1 cursor for --用游标
select distinct UserId from [你的表]
open cursor1
fetch next from cursor1 into @id
while @@fetch_status=0
begin
insert into #temp
select top 1 UserId,UpdateDate,Action from [你的表] where UserId = @id
order by UpdateDate desc
fetch next from cursor1 into @id
end
close cursor1
deallocate cursor1
select * from #temp
drop table #temp