0 votes
in MariaDB by
What is the usage of AVG() function in MariaDB database?

1 Answer

0 votes
by
MariaDB AVG() function is used to retrieve the average value of an expression.

AVG() returns NULL if there were no matching rows.

Syntax:

SELECT AVG(aggregate_expression)      

FROM tables      

[WHERE conditions];    

Or

SELECT expression1, expression2, ... expression_n,    

AVG (aggregate_expression)    

FROM tables    

[WHERE conditions]    

GROUP BY expression1, expression2, ... expression_n;     

Example

We have a table "Employee2", having the following data:

MariaDB Avg function 1

Let's retrieve the average salary of the employees from the table.

SELECT AVG(salary) AS "Average Salary"    

FROM Employee2;    

Output

MariaDB Avg function 2

Note: We can Use Average function With formula and ORDER BY clause too.
...