Código SQL:
Ver originalSELECT * FROM(
SELECT ROW_NUMBER()OVER (partition BY lastdate ORDER BY lastdate ASC) AS rn, * FROM
(
SELECT MAX(H.[SettledDate]) AS 'LastDate', J.[Player], CONVERT(VARCHAR(8), G.[GradedDate] , 108) AS 'Time', D.[RESULT], H.[RiskAmount], H.[WinAmount], G.[VisitorTeam] + ' @ ' +G.[HomeTeam] AS 'Teams',
P.[PeriodDescription], CONVERT(VARCHAR(MAX),G.[VisitorNumber]) + '/' + CONVERT(VARCHAR(MAX),G.[HomeNumber]) AS 'NumGame', D.[IdWager], W.[Description]
FROM GRADEDWAGERHEADER H, GRADEDWAGERDETAIL D, GRADEDGAME G, PERIOD P, AGENT A, WAGERTYPE W, PLAYER J
WHERE H.[IdWager] = D.[IdWager] AND
D.[IdGame] = G.[IdGame] AND
H.[IdAgent] = A.[IdAgent] AND
H.[IdPlayer] = J.[IdPlayer] AND
H.[IdWagerType] = W.[IdWagerType] AND
D.[IdSport] = P.[IdSport] AND
D.[Period] = P.[NumberOfPeriod] AND
H.[IdAgent] = 5585 AND
D.[IdWager] = 12683461 AND
D.[RESULT] = 1
GROUP BY J.[Player], G.[GradedDate], D.[RESULT], H.[RiskAmount], H.[WinAmount], G.[VisitorTeam], G.[HomeTeam],
P.[PeriodDescription], G.[VisitorNumber], G.[HomeNumber], D.[IdWager], W.[Description]
ORDER BY TIME DESC
) AS t1
) t2 WHERE rn=1