Sure. The AVG() function in SQL is used to calculate the average value of a column. The syntax for the AVG() function is:
SQL
AVG(column_name)
column_name is 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
employees table:
SQL
SELECT AVG(salary)
FROM employees;
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
employees table, but it will only consider each salary once:
SQL
SELECT AVG(DISTINCT salary)
FROM employees;
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:
To calculate the average age of customers.
To calculate the average number of items in an order.
To calculate the average time it takes to complete a task.
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.
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Sure. 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.