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.
We'll cover the following...
We'll cover the following...
Solution
The solution is given below:
MySQL
/* The query to find the average of marks in each subject */SELECT Subject, AVG(Marks) AS averageMarksFROM StudentGradesGROUP 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 theAVG()
function.Line 3: The
FROM
clause specifies the table,StudentGrades
.Line 4: In the
GROUP BY
clause, we specify theSubject
column to group the data by subject. ...