I believe that a simple summary query will give you the result set you want:
SELECT studentID, SUM(CASE WHEN Subject_Name = 'CHEMISTRY' THEN Marks ELSE 0 END) AS `CHEMISTRY`, SUM(CASE WHEN Subject_Name = 'BIOLOGY' THEN Marks ELSE 0 END) AS `BIOLOGY`, SUM(CASE WHEN Subject_Name = 'ENGLISH' THEN Marks ELSE 0 END) AS `ENGLISH`, SUM(CASE WHEN Subject_Name = 'MATH' THEN Marks ELSE 0 END) AS `MATH` FROM students GROUP BY studentID
You can replace and add / subtract the sample columns that I gave, with the names of the actual course subjects in your table.
Follow the link below for a working demo:
source share