AVG sql command is used to find out average value of a numeric field in a
table. Now let us apply this AVG command to this table and find out the
obtain by all the students. The AVG command will calculate the average
value of all the marks
Here we can use the Group
By command to find out the average mark obtained by each
SELECT class, avg( mark ) as avg_mark FROM `student` GROUP BY class
Please see the SQL SUM command to know the details
on uses of GROUP BY command and the
We can add condition to the sql command to get our desired result. We can add
one Where clause to the query to consider records
for which mark is more than some value ( say 55 )
SELECT avg( mark ) as avg_mark, class FROM student where mark > 55 GROUP BY class
Average mark in all subjects ( columns ) of a student ( row )
Now we need to calculate average mark of each student. Similarly we will display the total mark of each student with marks in all subjects. For this we will use different student table and dump of this table is available at the end of the page.
Here is the query.
SELECT id,name, social, math, science, sum(social + math + science ) as total, sum(social + math + science )/3 as avg from student3 group by id
My John Rob
Inserting Average mark in a new table.
We can store the average mark of each student in a new table for report generation.