Use the ISNULL() built-in function.
SELECT
MAX(STUDENTID) AS STUDENTID,
MAX(STUDENTSUBJECT) AS STUDENTSUBJECT,
ISNULL(MAX(YEAR1),"") As Year1,
ISNULL(MAX(MARKS1),"") As Marks1,
ISNULL(MAX(RANK1),"") As Rank1,
ISNULL(MAX(YEAR2),"") As Year2,
ISNULL(MAX(MARKS2),"") As Marks2,
ISNULL(MAX(RANK2),"") As Rank2,
ISNULL(MAX(YEAR3),"") As Year3,
ISNULL(MAX(MARKS3),"") As Marks3,
ISNULL(MAX(RANK3),"") As Rank3
FROM STUDENT
GROUP BY STUDENTSUBJECT
I do not understand why you use MAX(StudentID) and MAX(StudentSubject). Maybe you should use "Improve Question" and explain exactly what you are trying to get as a result (the requirements statement in simple terms).