Sobes.tech
Junior — Middle

Millised agregatsioonifunktsioonid on saadaval koos SQL-i GROUP BY käsuga kasutamiseks?

sobes.tech AI

Vastus AI-lt

In SQL, with the operator GROUP BY, aggregate functions are often used to compute summary values for groups. The main aggregate functions:

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

Example:

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

This query groups employees by departments and shows the number of employees and the average salary in each department.