...

/

Answer: Aggregate Records Using SUM

Answer: Aggregate Records Using SUM

Find a detailed explanation of using the SUM function to aggregate records in a table using SQL query.

Solution

The solution is given below:

Press + to interact
/* The query to find the sum of students' marks in Mathematics */
SELECT SUM(Marks) AS TotalMarksMaths
FROM StudentGrades
WHERE Subject = 'Mathematics';

Explanation

The explanation of the solution code is given below:

  • Line 2: The SELECT query finds the sum of students’ marks for Mathematics. We use AS to set an alias for the column.

  • Line 3: The FROM clause specifies the table, StudentGrades.

  • Line 4: In the WHERE clause, we specify the ...