日期:2014-05-18  浏览次数:20471 次

求查询为最大值的记录
declare @t table
(
  id int,  
  name varchar(1000),  
  addtime varchar(20) 
)

insert @t select 1,'a','2012-02-06'
union all select 2,'a','2012-06-21'
union all select 3,'a','2012-04-05'
union all select 4,'b','2012-09-21'
union all select 5,'b','2012-02-01'

select * from @t

--查询增加时间为最大值的记录如下:
-- id name addtime
-- 2 a 2012-06-21
-- 4 b 2012-09-21

------解决方案--------------------
SQL code
select * from @t t 
  where not exists(select 1 from @t where name=t.name and addtime>t.addtime)