SQL AVG Function
Category : TECH Author : Ankur Rastogi Date : Sun Mar 27 2016 Views : 41

SQL AVG function is used to find out the average value of the column value that is provided as input to AVG function. It will return the aggregated average of all the values.
AVG function is quite useful when we are doing some sort of analysis and needs to find the average value such as average salary, or avergae family strength in some city.
Syntax for SQL AVG function is
SELECT AVG(column_name) FROM table_name;
Let us have close look at it with the help of example.
Consider table hostel_list which contains the list of hostels.
+----+-------------------+-----------+----------+
| id | name | occupancy | capacity |
+----+-------------------+-----------+----------+
| 1 | ASHOK BHAVAN | 2 | 1090 |
| 2 | KAILASH BHAVAN | 2 | 990 |
| 3 | RUDRAKSH BHAVAN | 2 | 990 |
| 4 | KAVERI BHAVAN | 1 | 690 |
| 5 | BHAGIRATHI BHAVAN | 4 | 2140 |
| 6 | NARMADA BHAVAN | 6 | 3240 |
| 7 | GANGA BHAVAN | 1 | 780 |
| 8 | YAMUNA BHAVAN | 8 | 4580 |
+----+-------------------+-----------+----------+
Let us fint the average hostel capacity. SQL query for that will be
SELECT AVG(capacity) FROM hostel_list;
+---------------+
| AVG(capacity) |
+---------------+
| 1812.5000 |
+---------------+

SQL AVG function is used to find out the average value of the column value that is provided as input to AVG function. It will return the aggregated average of all the values.
AVG function is quite useful when we are doing some sort of analysis and needs to find the average value such as average salary, or avergae family strength in some city.
Syntax for SQL AVG function is
SELECT AVG(column_name) FROM table_name;
Let us have close look at it with the help of example.
Consider table hostel_list which contains the list of hostels.
+----+-------------------+-----------+----------+
| id | name | occupancy | capacity |
+----+-------------------+-----------+----------+
| 1 | ASHOK BHAVAN | 2 | 1090 |
| 2 | KAILASH BHAVAN | 2 | 990 |
| 3 | RUDRAKSH BHAVAN | 2 | 990 |
| 4 | KAVERI BHAVAN | 1 | 690 |
| 5 | BHAGIRATHI BHAVAN | 4 | 2140 |
| 6 | NARMADA BHAVAN | 6 | 3240 |
| 7 | GANGA BHAVAN | 1 | 780 |
| 8 | YAMUNA BHAVAN | 8 | 4580 |
+----+-------------------+-----------+----------+
Let us fint the average hostel capacity. SQL query for that will be
SELECT AVG(capacity) FROM hostel_list;
+---------------+
| AVG(capacity) |
+---------------+
| 1812.5000 |
+---------------+
Disclaimer: The above content reflect author’s personal views and do not reflect the views of OYEWIKI. Neither OYEWIKI nor any person/organization acting on its behalf is liable to accept any legal liability/responsibility for any error/mislead in this information or any information available on the website. This website in no way accepts the responsibility for any loss, injury, damage, discomfort or inconvenience caused as a result of reliance on any information provided on this website.
If you want to add more comments to the article or you see any thing incorrect please write a comment below and we will surely get back to you.