DECLARE @t Table(Name Varchar(30),[Year] Int, [Month] Int,Value Int)
Insert Into @t Values('JERRY' , 2012, 9, 100 )
Insert Into @t Values('JERRY', 2012, 9 , 120)
Insert Into @t Values('JERRY' , 2012, 9 , 130)
Insert Into @t Values('JERRY', 2012 , 8 , 20)
Insert Into @t Values('JERRY', 2011, 12 , 50)
Declare @LatestYr Int
Declare @LatestMonth Int
Select @LatestYr= Max([Year])From @t
Select @LatestMonth = Max([Month]) From @t Where [Year] = @LatestYr
Select * From @t
Where ([Year] = @LatestYr And [Month] = @LatestMonth)
結果

上記のクエリは、1人のユーザーに対してのみ機能します。また、複数のユーザーの場合、または同点の場合は失敗します。たとえば、次のシナリオを考えてみましょう

この場合、必要な出力は次のようになります。

そこで、このような状況に対処するために、以下の解決策を提案します。
解決策1
Select t.*
From @t t
Join
(
Select x.Name,x.Max_Year,y.Max_Month
From
( SELECT Name,Max_Year = Max([Year])
From @t
Group By Name
)x
Join
( SELECT Name,[Year],Max_Month= Max([Month])
From @t
Group By Name,[Year]
)y On x.Name = y.Name And x.Max_Year = y.[Year]
)x
On t.Name = x.Name
And t.[Year] = x.Max_Year
And t.[Month] = x.Max_Month
また
ソリューション2(SQL Server 2005以降)
Select Name,[Year],[Month],Value
From
(
Select *,Rn = Rank() Over(Partition By Name Order By [Year] desc, [Month] Desc)
From @t
)X Where X.Rn =1
ソリューション3(SQL Server 2005以降)
Select Name,[Year],[Month],Value
From
(
Select *,Rn = Dense_Rank() Over(Partition By Name Order By [Year] desc, [Month] Desc)
From @t
)X Where X.Rn =1
ddlは以下のとおりです
DECLARE @t Table(Name Varchar(30),[Year] Int, [Month] Int,Value Int)
Insert Into @t Values('JERRY' , 2012, 9, 100 )
Insert Into @t Values('JERRY', 2012, 9 , 120)
Insert Into @t Values('JERRY' , 2012, 9 , 130)
Insert Into @t Values('JERRY', 2012 , 8 , 20)
Insert Into @t Values('JERRY', 2011, 12 , 50)
Insert Into @t Values('FERRY' , 2010, 9, 100 )
Insert Into @t Values('FERRY', 2010, 9 , 120)
Insert Into @t Values('FERRY', 2010, 8 , 120)
Insert Into @t Values('JERRY1' , 2012, 9, 100 )
Insert Into @t Values('JERRY1', 2012, 9 , 120)
Insert Into @t Values('JERRY1' , 2012, 9 , 130)
Insert Into @t Values('JERRY1', 2012 , 8 , 20)
Insert Into @t Values('JERRY1', 2011, 12 , 50)
これがお役に立てば幸いです。ありがとう