How do you use the AVG() function to calculate the average value of a column in SQL?
How do you use the AVG() function to calculate the average value of a column in SQL?
478
30-Jun-2023
Updated on 01-Jul-2023
Aryan Kumar
01-Jul-2023Sure. The AVG() function in SQL is used to calculate the average value of a column. The syntax for the AVG() function is:
SQL
column_nameis the name of the column that you want to calculate the average of.The AVG() function will return the average value of all the non-NULL values in the column. For example, the following query will return the average salary of all employees in the
employeestable:SQL
The AVG() function can also be used with the DISTINCT keyword to calculate the average of unique values in a column. For example, the following query will return the average salary of all employees in the
employeestable, but it will only consider each salary once:SQL
The AVG() function is a versatile tool that can be used to calculate the average value of a column in SQL. It can be used to find the average salary of employees, the average price of products, or the average rating of movies.
Here are some other examples of how the AVG() function can be used:
The AVG() function is a powerful tool that can be used in a variety of ways. If you are working with data in SQL, then the AVG() function is a tool that you should definitely know about.