Tuesday, April 11, 2017

AVG() in SQL Server


SQL AVG() function used to return the average value of a column. The AVG() can only be applied on numeric type column. The AVG() determines the average of all the non-NULL values in the columns, NULL values are ignored.

Syntax:

     
            SELECT AVG(ALL | DISTINCT column_name) FROM table_name


column_name is the name of the column of which average is to be calculated.

table_name is the name of the table


Example 1: AVG() on column which does not have any NULL value.

SELECT * FROM TempEmployeePayHistory



SELECT AVG(Rate) FROM TempEmployeePayHistory



Example 2:
AVG() on column having NULL values.

SELECT * FROM TempEmployeePayHistory



SELECT AVG(Rate) FROM TempEmployeePayHistory



Example 3:
AVG() on non-numeric column.





Share This
Previous Post
Next Post

TekGrabs, established in 2017, is in the business of sharing Information. It provides news, articles and photos about the different technologies, inventions in different domains. Provides information on programming and databases.

0 comments: