Sobes.tech
Junior

What do you know about aggregate functions?

sobes.tech AI

Answer from AI

An aggregate function performs calculations on a set of values and returns a single scalar value.

Examples of aggregate functions in SQL:

  • 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.

They are typically used with the GROUP BY operator to group rows to which aggregation is applied.

Example of an SQL query with an aggregate function:

SELECT
    COUNT(*) AS total_users,
    AVG(age) AS average_age
FROM
    users
WHERE
    status = 'active'
GROUP BY
    city;
What do you know about aggregate functions? — PHP - sobes.tech