if object_id('[tb]') is not null drop table [tb] go create table [tb]([Id] int,[Name] varchar(3),[Result] int,[Date] datetime) insert [tb] select 1,'001',90,'2013-11-10' union all select 2,'002',85,'2013-11-10' union all select 3,'003',87,'2013-11-10' union all select 4,'001',95,'2013-11-15' union all select 5,'002',83,'2013-11-15' union all select 6,'003',89,'2013-11-15' union all select 7,'001',92,'2013-11-20' union ALL select 8,'002',83,'2013-11-20' union all select 9,'003',88,'2013-11-20' go
;with t as ( select *, ROW_NUMBER() over(partition by [Name] order by [Date] desc) rownum from tb )
select t1.Name,t1.Result, case when t1.[Result] > t2.[Result] then '上升' when t1.[Result] = t2.[Result] then '持平' when t1.[Result] < t2.[Result] then '下降' end flag from t t1 left join t t2 on t1.Name = t2.Name and t1.rownum = t2.rownum - 1 and t2.rownum = 2 where t1.rownum = 1 /* Name Result flag 001 92 下降 002 83 持平 003 88 下降 */