Answer: Aggregate Records Using SUM
Explore how to apply the SQL SUM aggregate function to calculate total values from filtered data using aliases and conditional logic. Understand the role of SELECT queries, WHERE clauses, and CASE statements for flexible summations in SQL. Gain practical skills to solve similar interview questions involving aggregate functions.
Solution
The solution is given below:
Explanation
The explanation of the solution code is given below:
Line 2: The
SELECTquery finds the sum of students’ marks for Mathematics. We useASto set an alias for the column.Line 3: The
FROMclause specifies the table,StudentGrades.Line 4: In the
WHEREclause, we specify the subject to filter the data. ...