Aggregate Function in SQL || Aggregate Function in SQL with Example
An aggregate function in SQL performs a calculation on multiple values and returns a single value.
SQL provides many aggregate functions that include avg, count, sum, min, max, etc.
An aggregate function ignores NULL values when it performs the calculation, aside from the count function.
TUTORIAL IN HINDI:
Type of Aggregate function:
1) Count
2) Min
3) Max
4) Sum
5) Avg
1) Count():
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.
Count function uses the Count(*) that returns the count of all the rows in a specified table.
Count(*) considers duplicate and Null.
Example:
SELECT COUNT(*)
FROM Employee;
2) Min():
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.
Example:
SELECT MIN(Salary)
FROM Employee;
3) Max():
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.
Example:
SELECT MAX(Salary)
FROM Employee;
4) Sum():
Sum function is used to calculate the sum of all selected columns. It works on numeric fields only.
Example:
SELECT SUM(Salary)
FROM Employee;
5) Avg():
The AVG function is used to calculate the average value of the numeric type. AVG function returns the average of all non-Null values.
Example:
SELECT AVG(Salary)
FROM Employee;
0 Comments