The AVG function of MySQL is used to find the average of the fields in various records.
To understand the AVG feature consider the EMPLOYEE_TBL table has the following records:
Mysql> SELECT * from EMPLOYEE_TBL;
+------+------+------------+--------------------+
| id | name | work_date | daily_typing_pages
| +------+------+------------+--------------------+
| 1 | John | 2007-01-24 | The |
| 2 | Ram | 2007-05-27 | The |
| 3 | Jack | 2007-05-06 | 170 |
| 3 | Jack | 2007-04-06 | |
| 4 | Jill | 2007-04-06 | The |
| 5 | Zara | 2007-06-06 | A |
| 5 | Zara | 2007-02-06 | |
+------+------+------------+--------------------+
7 rows in Set (0.00 sec)
Now, assuming that you want to calculate the average of all the dialy_typing_pages based on the table above, you can use the following command:
Mysql> SELECT AVG (daily_typing_pages)
-> from Employee_tbl;
+-------------------------+
| AVG (daily_typing_pages) |
+-------------------------+
| 230.0000 |
+-------------------------+
1 row in Set (0.03 sec)
You can set various records using the GROUP BY clause on average. The following example will take an average of one person's all relevant records, each per person's average page paper.
mysql> SELECT name, AVG (daily_typing_pages)
-> from Employee_tbl GROUP by name;
+------+-------------------------+
| name | AVG (daily_typing_pages) |
+------+-------------------------+
| Jack | 135.0000 |
| Jill | 220.0000 |
| John | 250.0000 |
| Ram | 220.0000 |
| Zara | 325.0000 |
+------+-------------------------+
5 rows in Set (0.20 sec)