The below SQL query sums up each penalty mark per question in a session:
SELECT s.SessionId,q.QuestionId,SUM(pm.PenaltyMarks)
FROM Session s
INNER JOIN Question q ON s.SessionId = q.SessionId
INNER JOIN Penalty_Marks pm ON q.QuestionId = pm.QuestionId
WHERE (s.SessionId = 30)
GROUP BY s.SessionId,q.QuestionId
Below is what the output displays:
SessionId QuestionId Sum(pm.PenaltyMarks)
30 77 4
30 38 3
30 39 4
But what I want to happen is now sum up all of the penalty marks within the Session. So in the above example it will add up the penalty marks together for session 30 to output the total penalty marks as 11. But my question is how can this be achieved?
So below is what it should look like:
SessionId TotalPenaltyMarks
30 11
remove
q.QuestionIdThe
GROUP BYclause is already optional since you are already filtering for a specificSessionId.