Krivalar Tutorials 
Krivalar Tutorials



SQL AVG Function - to calculate average

<<Previous - SQL COUNT() Function

Next - SQL SUM() Function >>






SQL AVG() function

SQL AVG() function finds the average value of a given numeric column.

SQL AVG() Syntax


SELECT AVG(column-name) FROM  Table-name
WHERE condition;

Example

Demo student_mark table from collegedb database.

mysql> SELECT * FROM Student_Mark;
+--------+---------+-----------+------+
| RollNo | Name    | City      | Mark |
+--------+---------+-----------+------+
|    101 | Sakthi  | Chennai   |   80 |
|    102 | Bala    | Chennai   |   86 |
|    103 | Chandra | Bangalore |   89 |
|    104 | Madhan  | Goa       |   80 |
|    105 | Jose    | Kerala    |   82 |
|    106 | Jithu   | Kerala    |   85 |
|    107 | Veni    | Bangalore |   85 |
+--------+---------+-----------+------+
7 rows in set (0.00 sec)

Following query statement find the average value in the selected Mark column

mysql> SELECT AVG(Mark) FROM Student_Mark;
+-----------+
| AVG(Mark) |
+-----------+
|   83.8571 |
+-----------+
1 row in set (0.01 sec)

<<Previous - SQL COUNT() Function

Next - SQL SUM() Function >>









Searching using Binary Search Tree