首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

怎么删除A表中,A_1字段相同的记录,但还保留一条(A_Time字段时间最大的那一条)

2012-01-06 
如何删除A表中,A_1字段相同的记录,但还保留一条(A_Time字段时间最大的那一条)?如何删除A表中,A_1字段相同

如何删除A表中,A_1字段相同的记录,但还保留一条(A_Time字段时间最大的那一条)?
如何删除A表中,A_1字段相同的记录,但还保留一条(A_Time字段时间最大的那一条)?

[解决办法]
declare @t table(id int identity,A_1 nvarchar(50),
date_time datetime)
insert into @t select 'a ', '2007-03-02 ' union all
select 'a ', '2007-03-01 ' union all
select 'b ', '2007-03-01 ' union all
select 'b ', '2007-03-02 ' union all
select 'c ', '2007-03-03 '
select idd=identity(int,1,1),A_1,date_time into #t from @t order by date_time desc
--select * from #t
--select min([id]) from @t order date_time desc group by A_1
delete from #t where idd not in (select min([id]) from @t group by A_1)
select * from #t
drop table #t

热点排行