1The following are the most commonly used SQL aggregate functions:
2AVG – calculates the average of a set of values.
3COUNT – counts rows in a specified table or view.
4MIN – gets the minimum value in a set of values.
5MAX – gets the maximum value in a set of values.
6SUM – calculates the sum of values.
7
8The following illustrates the syntax of an aggregate function:
9aggregate_function_name(DISTINCT | ALL expression)
10
11In this syntax;
12
13First, specify the name of an aggregate function that you want to use such as AVG, SUM, and MAX.
14Second, use DISTINCT if you want only distinct values are considered in the calculation or ALL if all values are considered in the calculation. By default, ALL is used if you don’t specify any modifier.
15Third, the expression can be a column of a table or an expression that consists of multiple columns with arithmetic operators.
16
17
1MAX – To find the number of the maximum values in the SQL table.
2
3MIN – Number of the minimum values in the table.
4
5COUNT – Get the number of count values in the SQL table.
6
7AVG – Find average values in the SQL table.
8
9SUM – Return the summation of all non-null values in the SQL table.
1 -- Emp_Id is a Column Name
2 -- employee_tble is Table Name;
3
4select count(Emp_Id) from employee_tbl;
5
6select min(Salary) from employee_tbl;
7
8select max(Salary) from employee_tbl;
9
10select sum(Salary) from employee_tbl;
11
12select avg(Salary) from employee_tbl;
1--- GROUP FUNCTION | MULTI ROW FUNCTION | AGGREGATE FUNCTION
2--- COUNT , MAX , MIN , SUM , AVG
1--- GROUP FUNCTION | MULTI ROW FUNCTION | AGGREGATE FUNCTION
2--- COUNT , MAX , MIN , SUM , AVG
3
1• Single Row Functions:(Lower, Upper, Substr, Length)
2function that will run for each row and
3return value for each row.
4
5Multiple Row Functions (Group functions, Aggregate functions):
6(Count, MIN , MAX, AVG, SUM)
7will run for multiple rows and return a single value