...

/

Answer: The GROUP BY Clause and the AVG Function

Answer: The GROUP BY Clause and the AVG Function

Find a detailed explanation of how to use the GROUP BY clause to group the records in SQL query.

Solution

The solution is given below:

Press + to interact
/* The query to find the average of marks in each subject */
SELECT Subject, AVG(Marks) AS averageMarks
FROM StudentGrades
GROUP BY Subject;

Explanation

The explanation of the solution code is given below:

  • Line 2: The SELECT query finds the average of students’ marks for each subject using the AVG() function.

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

  • Line 4: In the GROUP BY clause, ...