HomeInterview QuestionsHow do I find the total marks for each subject in …

How do I find the total marks for each subject in SQL?

🟢 Easy Coding Fresher level
1Times asked
Jul 2026Last seen
Jul 2026First seen

💡 Model Answer

To calculate the total marks for each subject, you need to aggregate the marks column grouped by the subject column. Assuming you have a table named student_marks with columns student_id, subject, and marks, the query would look like:

SELECT subject, SUM(marks) AS total_marks

FROM student_marks

GROUP BY subject;

This query sums the marks for every distinct subject. If you also want to include subjects that have no marks yet, you could join with a subjects table and use a LEFT JOIN. The complexity is O(n) where n is the number of rows in student_marks, because the database scans each row once and performs a hash or sort on the subject key. Indexing the subject column can improve performance for large datasets. The result will list each subject and its total marks, which can be used for reporting or further analysis.

This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.

🎤 Get questions like this answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.

Get Assisting AI — Starts at ₹500