日期:2014-05-18 浏览次数:20534 次
select a.name,date a.from( select row_number()over(partition by name order by cast(right(date,2) as int) desc) as num,*from tbl)a where num=1
------解决方案--------------------
CREATE TABLE #t(NAME CHAR(2),dates DATE) insert into #t select 'A', '201201' union all select 'A', '201202' union all select 'A', '201203' union all select 'B', '201202' union all select 'B', '201203' union all select 'B', '201204' union all select 'C', '201203' union all select 'C', '201204' union all select 'C', '201205' SELECT NAME,MAX(dates) FROM #t GROUP BY NAME
------解决方案--------------------
select * from A t where not exists(select 1 from name=t.name and [date]>t.[date])
------解决方案--------------------