Cheap VPS & Xen Server


Residential Proxy Network - Hourly & Monthly Packages

MySQL avg()


The MySQL avg() function is used to return the average value of an expression.

Syntax:

  1. SELECT AVG(aggregate_expression)
  2. FROM tables
  3. [WHERE conditions];

Parameter explanation

aggregate_expression: It specifies the column or expression that will be averaged.

table_name: It specifies the tables, from where you want to retrieve records. There must be at least one table listed in the FROM clause.

WHERE conditions: It is optional. It specifies the conditions that must be fulfilled for the records to be selected.

MySQL avg() function example

Consider a table named “employees”, having the following data.

mysqlaverage1

Execute the following query:

  1. SELECT AVG(working_hours) AS “Avg working hours”
  2. FROM employees
  3. WHERE working_hours > 5;

Output:

mysqlaverage2

Comments

comments