Computer Science, asked by Adil31343, 1 year ago

explain SQL aggregate functions with example

Answers

Answered by Madan1231
7
SQL Aggregate Functions:

AVG() – Returns the average value
COUNT() – Returns the number of rows
MAX() – Returns the largest value
MIN() – Returns the smallest value
SUM() – Returns the sum

Examples



1) The AVG () Function:

The AVG () function returns the average value of a numeric column.

Syntax:

SELECT AVG (Column_Name)

FROM <Table_Name>;

2) The COUNT () Function:

The COUNT () function returns the number of rows that matches a specified criteria.We Can count the Number of rows using following 3 types:

1) COUNT (Column_Name)

2) COUNT (*)

3) COUNT (DISTINCT Column_Name)

1) Syntax:

SELECT COUNT (Column_Name)

FROM <Table_Name>;
3) The MAX () Function:

The MAX () function returns the largest value of the selected column.

Syntax:

SELECT MAX (Column_Name)

FROM <Table_Name>;

 SELECT MAX (Sal) FROM EMP;

 SELECT DeptNo, Max (Sal) FROM EMP

GROUP BY DeptNo

ORDER BY DeptNo;

4) The MIN () Function:

The MIN () function returns the smallest value of the selected column.

Syntax:

SELECT MIN (Column_Name) FROM <Table_Name>;

SELECT MIN (Sal) FROM EMP;

SELECT DeptNo, Min (Sal) FROM EMP

GROUP BY DeptNo

ORDER BY DeptNo;

5) The SUM () Function:

The SUM () function returns the total sum of a numeric column.

Syntax:

SELECT SUM (Column_Name) FROM <Table_Name>;


Similar questions