34,590
社区成员
发帖
与我相关
我的任务
分享
--> 测试数据: #T
if object_id('tempdb.dbo.#T') is not null drop table #T
create table #T (FILE1 varchar(2),FILE2 int,FILE3 int,FILEDATE datetime)
insert into #T
select 'AA',1,2,'2008-4-4' union all
select 'AA',2,3,'2008-4-5' union all
select 'AA',2,3,'2008-4-6' union all
select 'BB',2,3,'2008-5-5' union all
select 'BB',2,3,'2008-5-8' union all
select 'CC',2,3,'2008-6-1'
select * from #t a where not exists( select 1 from #t where FILE1=a.FILE1 and FILEDATE>a.FILEDATE)
/*
AA 2 3 2008-04-06 00:00:00.000
BB 2 3 2008-05-08 00:00:00.000
CC 2 3 2008-06-01 00:00:00.000
*/
--> 测试数据: #T
if object_id('tempdb.dbo.#T') is not null drop table #T
create table #T (FILE1 varchar(2),FILE2 int,FILE3 int,FILEDTAE datetime)
insert into #T
select 'AA',1,2,'2008-4-4' union all
select 'AA',2,3,'2008-4-5' union all
select 'AA',2,3,'2008-4-6' union all
select 'BB',2,3,'2008-5-5' union all
select 'BB',2,3,'2008-5-8' union all
select 'CC',2,3,'2008-6-1'
select * from #T as t where FILEDTAE=(select max(FILEDTAE) from #T where FILE1=t.FILE1) order by 1
/*
AA 2 3 2008-4-6
BB 2 3 2008-5-8
CC 2 3 2008-6-1
*/