Aggregate Functions

Purpose: Aggregate functions allow you to perform calculations on a set of values, returning a single summary value.Common Functions:

  • SUM(): Returns the total sum of a numeric column.
  • AVG(): Returns the average value of a numeric column.
  • COUNT(): Counts the number of rows that match a specified condition.
  • MAX(): Returns the maximum value in a set.
  • MIN(): Returns the minimum value in a set.

Example:

SELECT department_id, AVG(salary) AS avg_salary
FROM employees
GROUP BY department_id;

Explanation: This calculates the average salary for each department, grouping results by department_id. The AVG() function computes the average, and the results will have one row for each department.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *