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
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
SELECTquery finds the average of students’ marks for each subject using theAVG()function.Line 3: The
FROMclause specifies the table,StudentGrades.Line 4: In the
GROUP BYclause, we specify theSubjectcolumn to group the data by subject. ...
Ask