SQL Aggregate FunctionsLast Updated : 10 Feb 2026 ![]()
Why do we use Aggregate Functions? A crucial part of database management systems are aggregate functions. They enable us to swiftly and effectively do computations on big data sets. These tasks include, for instance, managing inventory levels, generating statistical reports, and conducting financial analysis. Using aggregate functions also helps us comprehend the data we are dealing with better. For instance, finding the total sales for a specific period of time or figuring out the average price of every product in our inventory is simple. We would have to manually filter through each data point if there were no aggregate functions, which would be laborious and prone to mistake. All things considered, aggregate functions are necessary for anyone dealing with big data and trying to extract useful data from it. Types of SQL Aggregation Function![]() 1. COUNT FUNCTION
Syntax Sample table: PRODUCT_MAST
Example: COUNT() Output: 10 Example: COUNT with WHERE Output: 7 Example: COUNT() with DISTINCT Output: 3 Example: COUNT() with GROUP BY Output: Com1 5 Com2 3 Com3 2 Example: COUNT() with HAVING Output: Com1 5 Com2 3 2. SUM FunctionSum function is used to calculate the sum of all selected columns. It works on numeric fields only. Syntax Example: SUM() Output: 670 Example: SUM() with WHERE Output: 320 Example: SUM() with GROUP BY Output: Com1 150 Com2 170 Example: SUM() with HAVING Output: Com1 335 Com3 170 3. AVG functionThe AVG function is used to calculate the average value of the numeric type. AVG function returns the average of all non-Null values. Syntax Example: Output: 67.00 4. MAX FunctionMAX function is used to find the maximum value of a certain column. This function determines the largest value of all selected values of a column. Syntax Example: 30 5. MIN FunctionMIN function is used to find the minimum value of a certain column. This function determines the smallest value of all selected values of a column. Syntax Example: Output: 10 Example of Aggregate FunctionsSQL Code: Output: TotalStudents 9 TotalMarks 900 AverageMarks 400 HighestMarks 800 LowestMarks 300 Conclusion:In SQL, an aggregate function calculates several values and returns a single result. Numerous aggregate functions, such as avg, count, sum, min, max, and others, are available in SQL. With the exception of the count function, an aggregate function conducts the computation ignoring NULL values. Next TopicDBMS SQL Join |
We request you to subscribe our newsletter for upcoming updates.