SQL AVG() Function - The Coding Shala
Home >> Learn SQL >> SQL AVG() function
The following 'emp' table is used for the examples -
The following SQL query will return the average salary of employees who are from the same city -
SQL AVG() Function
The SQL AVG() Function returns the average value of a numeric column.
SQL AVG() Syntax
The basic syntax of SQL AVG() is as follows -
SELECT AVG(column_name) FROM table_name WHERE condition;
The following 'emp' table is used for the examples -
emp_id emp_name city dept_no salary 1 Akshay Pune 101 50000 3 Nikhil Pune 101 51000 5 Mohit Delhi 103 40000 6 Shubham Surat 105 42000 7 Akash Mumbai 106 45000
SQL AVG() Examples
The following SQL query will return the average salary of all the employees using SQL AVG() Function -
SQL >> select avg(salary) as 'Average Salary' from emp; Output >> Average Salary 45600
The following SQL query will return the average salary of employees who are from the same city -
SQL >>select city, avg(salary) as 'Average Salary' from emp group by city; Output >> city Average Salary Delhi 40000 Mumbai 45000 Pune 50500 Surat 42000
Other Posts You May Like
Comments
Post a Comment