What are aggregate functions in SQL Server and its Types
Loading
What are aggregate functions in SQL Server and its Types
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Harshit PandeyPosted Aug 5, 2025, 3:50 AM
In SQL Server, aggregate functions are built-in functions that perform a calculation on a set of values and return a single summarized result. They are commonly used with the
GROUP BYclause to group rows that share the same values into summary rows.Common Types of Aggregate Functions:
SUM()Calculates the total sum of a numeric column.
Example:
SELECT SUM(Salary) FROM Employees;AVG()Returns the average value of a numeric column.
Example:
SELECT AVG(Age) FROM Users;COUNT()Returns the number of rows that match a specified condition.
Example:
SELECT COUNT(*) FROM Orders;MIN()Returns the smallest value in a column.
Example:
SELECT MIN(Price) FROM Products;MAX()Returns the largest value in a column.
Example:
SELECT MAX(Score) FROM Results;COUNT(DISTINCT column)Returns the number of unique (non-duplicate) values.
Example:
SELECT COUNT(DISTINCT Department) FROM Employees;Note: Aggregate functions ignore
NULLvalues (exceptCOUNT(*), which counts all rows).Sandhiya PriyaPosted Aug 6, 2025, 11:52 AM
Aggregate functions in SQL Server are used to perform calculations on multiple values and return a single summary value. They are commonly used with
GROUP BYfor reporting and analysis.Here are the most commonly used aggregate functions:
1.
SUM()Returns the total sum of a numeric column.
2.
AVG()Returns the average value.
3.
COUNT()Returns the number of rows.
4.
MAX()Returns the maximum value.
5.
MIN()Returns the minimum value.
Example with GROUP BY:
This shows the average salary per department.
Cynthia SathuragiriPosted Aug 5, 2025, 5:03 AM
Aggregate functions are used to calculate a single value from a group of values in a table, like total, average, minimum, or maximum.
COUNT() – Counts how many rows or values are there.
SUM() – Adds up all the numbers in a column.
AVG() – Finds the average of numbers.
MIN() – Finds the smallest value.
MAX() – Finds the largest value.