Which of the following is an aggregate function in SQL?

2023

Which of the following is an aggregate function in SQL?

  1. A.

    CONCAT()

  2. B.

    AVG()

  3. C.

    SUBSTRING()

  4. D.

    LENGTH()

  5. E.

    NOW()

Attempted by 64 students.

Show answer & explanation

Correct answer: B

Concept

In SQL, an aggregate function takes a set (column) of values across many rows and collapses it into a single summary value. Common aggregates are AVG, SUM, COUNT, MIN and MAX. They differ from scalar functions, which operate on one value (per row) and return one value per row.

Applying it here

Examine what each function does and whether it summarises many rows into one value:

  • AVG() takes a column of numeric values across rows and returns their single arithmetic mean, so it is an aggregate function.

  • CONCAT() joins two or more strings within a single row and returns one string per row.

  • SUBSTRING() extracts a portion of one string and returns one string per row.

  • LENGTH() returns the character count of one string, one value per row.

  • NOW() returns the current date and time and is unrelated to summarising rows.

Conclusion

Only AVG() consumes a group of rows and produces a single aggregated result, so AVG() is the aggregate function.

Explore the full course: Niacl Ao It Specialist