SQL AVG() Function
SQL AVG() function returns the average value of a numeric column of a table and it ignores NULL values during calculation.
Syntax
SELECT AVG(columnName) FROM TableName
In this article we will consider Student table to check how AVG() function works. We will calculate average value of Fees column.
SELECT AVG(Fees) FROM StudentĀ
So, average value of Fees column is 15766.
We can also use GROUP BY clause with AVG() function to calculate the average value as follows.
SELECT FirstName, AVG(Fees) AS FEES FROM Student GROUP BY FirstName
Here we are selecting FirstName column with average value of Fees column by grouping FirstName column. So if you can observeĀ in above output for student Gigi and Roberto their Fees column is calculated on an average basis and returned average fees for each one.
Reference: Manzoor Siddiqui [www.SQLServerLog.com]