SQL -Structured Query Language - Sql Select - Select - Average Tutorial
To retrieve an average number of a numeric column in a record from the existing created table. Then we can use a ' SELECT ' statement with AVG() function.
Without condition
Syntax-
The basic syntax of the SELECT statement with AVG() function is given below –
SELECT AVG(numeric_column_name) FROM table_name;
For example-
- Using numeric column name
SELECT AVG(salary) FROM employees;
Here it will retrieve the average salary in the record from the employees' table.
We can use whereas Condition / Clause in a select statement such as WHERE, GROUP BY, HAVING, ORDER BY, ETC.
With condition (USING WHERE)
Syntax-
The basic syntax of the ‘ SELECT ‘ statement with AVG() function using WHERE condition is given below –
SELECT AVG(numeric_column_name) FROM table_name WHERE [CONDITION] ;
For example-
- Using numeric column name
SELECT AVG(salary) FROM employees WHERE employee_id>150;
Here it will retrieve the average salary from the employees' table whose employee_id is greater than 150.