Explain MySQL Aggregate Functions.

Answer

Aggregate functions in MySQL are a group of functions that are used to operate on a set of values. These functions ignore NULL values unless specified. Functions like AVG(), MIN(), MAX(), COUNT() etc fall under this category. As they operate on a set of values, if no Group by clause is used, it applies to all rows.

Explain the following functions with an example.

AVG()
Returns the average of the parameter passed. Returns 0 if no matching rows found.

Example:
Avg(salary)

COUNT()
Counts the number of NON NULL values of the parameter passed. Returns 0 if no matching rows found.

Example:
Select employee_id, COUNT(*) from table_name;

MAX()
Returns the maximum value of the parameter passed. Returns 0 if no matching rows found.

Example:
Select MAX(employee_salary) from table_name

MIN()
Returns the minimun value of the parameter passed. Returns 0 if no matching rows found.

Example:
Select MIN(employee_salary) from table_name

SUM()
Returns the sum of the parameter passed. Returns NULL if no matching rows found.

Example:
Select SUM(employee_salary) from table_name

All sql dba Questions

Ask your interview questions on sql-dba

Write Your comment or Questions if you want the answers on sql-dba from sql-dba Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---