mySql  avg() function

the mysql avg (average) function is an aggregate function that allows you to calculate the average value of a set of values or an expression.

mysql avg() function syntax

         select    avg(column_name or expre)    from   table_name;

avg() returns null if there were no matching rows.


below is a selection from the "users" table:

useridfirstnamesalarybonus
1sandeep10,0001000
2ankit20,0002000
3ram30,0003000
4vikram12,0002000

mysql average function example

the following mysql statement gets the average value of the 'bonus' from the "users" table:

               
               select    avg(bonus)    as   bonusaverage      from    users;

note : the null value is not included in the calculation of the avg function.

output: try it yourself