In this post, I will show you how to convert column to row in SQL. For this post, I am going to use the following table which has three column stu_name,sibject and marks
SELECT stu_name,
MAX(CASE WHEN subject = 'ECO' THEN marks
ELSE 0
END) ECO,
MAX(CASE WHEN subject = 'HIS' THEN marks
ELSE 0
END) HIS,
MAX(CASE WHEN subject = 'MAT' THEN marks
ELSE 0
END) MAT,
MAX(CASE WHEN subject = 'GEO' THEN marks
ELSE 0
END) GEO,
MAX(CASE WHEN subject = 'SCI' THEN marks
ELSE 0
END) SCI
FROM col_to_rows
GROUP BY stu_name