Sobes.tech
Junior

What are aggregate functions?

sobes.tech AI

Answer from AI

Aggregate functions in SQL are functions that perform calculations on a set of values and return a single final value. They are often used together with the GROUP BY operator to group data.

Main aggregate functions:

  • COUNT() — counts the number of rows.
  • SUM() — calculates the sum of values.
  • AVG() — calculates the average value.
  • MIN() — finds the minimum value.
  • MAX() — finds the maximum value.

Example of usage:

SELECT department, COUNT(*) AS employee_count, AVG(salary) AS avg_salary
FROM employees
GROUP BY department;

This query counts the number of employees and the average salary for each department.

What are aggregate functions? — PHP - sobes.tech