SQL AVG Function



SQL AVG function is used to find out the average of a field in various records.

Consider an EMPLOYEE table, which is having the following records:

SQL> SELECT * FROM EMPLOYEE;

After running the above query we will get below output –

+----+----------+-----+-----------+----------+----------+
| ID | ENAME    | AGE | ADDRESS   | SALARY   |  ENTRY   |    
+----+----------+-----+-----------+----------+----------+
|  1 | Ramesh   |  32 | Kota      |  2000.00 |     5    |
|  2 | Raj      |  23 | Delhi     |  1500.00 |     6    |
|  3 | Anand    |  21 | Karachi   |  2000.00 |     4    |
|  4 | Saurabh  |  25 | Mumbai    |  6500.00 |     7    |
|  5 | Poonam   |  29 | Bhopal    |  8500.00 |     5    |
|  6 | Komal    |  23 | Pune      |  4500.00 |     3    |
|  7 | Omkar    |  24 | Indore    | 10000.00 |     5    |
+----+----------+-----+-----------+----------+----------+
7 rows in set (0.00 sec)

Now we need to calculate the average number of entries made by Employee then you can use below query –

SQL> SELECT AVG(ENTRY) FROM EMPLOYEE;

+------------+
| AVG(ENTRY) |
+------------+
|     5.0000 |
+------------+

1 row in set (0.01 sec)