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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Harshit PandeyRank #582 · 4.1K reputationPosted Aug 4, 2025, 11:50 PM EDT
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).Cynthia SathuragiriRank #937 · 2.2K reputationPosted Aug 5, 2025, 1:03 AM EDT
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.
Sandhiya PriyaRank #26 · 43.2K reputationPosted Aug 6, 2025, 7:52 AM EDT
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.
SELECT SUM(Salary) AS TotalSalary FROM Employees;2.
AVG()Returns the average value.
SELECT AVG(Salary) AS AverageSalary FROM Employees;3.
COUNT()Returns the number of rows.
SELECT COUNT(*) AS TotalEmployees FROM Employees;4.
MAX()Returns the maximum value.
SELECT MAX(Salary) AS HighestSalary FROM Employees;5.
MIN()Returns the minimum value.
SELECT MIN(Salary) AS LowestSalary FROM Employees;Example with GROUP BY:
SELECT Department, AVG(Salary) AS AvgSalary FROM Employees GROUP BY Department;This shows the average salary per department.