HI yogeshc,
Refer the below Test Query For your reference.
SQL
DECLARE @Sttudent_Id INT
SET @Sttudent_Id = 10003
SELECT * INTO #TempMarks
FROM (SELECT *
FROM (SELECT [Subject],[Term],[Obt_Marks]
FROM Marks WHERE StudentId = @Sttudent_Id) as tbl
PIVOT(SUM(Obt_Marks) FOR [Term] IN ([1],[2])) as PVT
) AS S
SELECT *,[1]+[2] as 'G Total' FROM #TempMarks
UNION ALL
SELECT 'Total',SUM([1]),SUM([2]), SUM([1]+[2])FROM #TempMarks
drop table #TempMarks
Output
Subject |
1 |
2 |
G Total |
DRAWING |
17 |
19 |
36 |
ENGLISH |
19 |
15 |
34 |
EVS |
18 |
18 |
36 |
GEN. KNOWLEDGE |
18 |
20 |
38 |
HINDI |
18 |
16 |
34 |
MATHEMATICS |
19 |
19 |
38 |
MORAL EDUCATION |
19 |
20 |
39 |
Total |
128 |
127 |
255 |