DEV Community

sonam ojha
sonam ojha

Posted on

Explain the concept of an aggregate function in SQL. Provide examples of aggregate functions.

SQL aggregation function is used to perform the calculations on multiple rows of a single column of a table. It returns a single value.

Types of SQL Aggregation Function

COUNT FUNCTION :- COUNT function is used to Count the number of rows in a database table. It can work on both numeric and non-numeric data types.

SELECT COUNT(*)  
FROM TABLE_NAME;  
Enter fullscreen mode Exit fullscreen mode

SUM FUNCTION :- Sum function is used to calculate the sum of all selected columns. It works on numeric fields only.

SELECT SUM(COLUMN)  
FROM TABLE_NAME;  
Enter fullscreen mode Exit fullscreen mode

AVG FUNCTION :- The AVG function is used to calculate the average value of the numeric type. AVG function returns the average of all non-Null values.

SELECT AVG(COLUMN)  
FROM TABLE_NAME;  
Enter fullscreen mode Exit fullscreen mode

MAX FUNCTION :-
MAX 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.


SELECT MAX(COLUMN)  
FROM TABLE_NAME;  
Enter fullscreen mode Exit fullscreen mode

MIN FUNCTION :- MIN 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.

SELECT MIN(COLUMN)  
FROM TABLE_NAME;  
Enter fullscreen mode Exit fullscreen mode

Top comments (0)