Вы можете использовать apply
:
SELECT StudentCode, CourseCode,GroupCode, Score, StudentRank, t1.What_u_want
FROM Table t OUTER APPLY
( SELECT TOP 1 t1.Score AS What_u_want
FROM Table t1
WHERE t1.CourseCode = t.CourseCode AND
t1.GroupCode = t.GroupCode AND
t1.StudentRank < t.StudentRank
ORDER BY t1.StudentRank DESC
);
Однако, то же самое можно было бы достичь с помощью корреляции подхода:
SELECT StudentCode, CourseCode,GroupCode, Score, StudentRank,
(SELECT TOP 1 t1.Score AS What_u_want
FROM Table t1
WHERE t1.CourseCode = t.CourseCode AND
t1.GroupCode = t.GroupCode AND
t1.StudentRank < t.StudentRank
ORDER BY t1.StudentRank DESC
) What_u_want
FROM Table t1;