SQL - AGGREGATE FUNCTIONS

The following are the most commonly used SQL aggregate functions:

  • AVG – calculates the average of a set of values.

  • COUNT – counts rows in a specified table or view.

  • MIN – gets the minimum value in a set of values.

  • MAX – gets the maximum value in a set of values.

  • SUM – calculates the sum of values.

AVG

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

SYNTAX

99.png

EXAMPLE

Let’s consider a demo database and table.

100.png
101.png

Figure 29.2. AGGREGATE QUERY & OUTPUT

Figure 29.1. Select * from SalaryInfo;

 
 

COUNT

The COUNT () function counts the number of rows that matches a specified condition.

SYNTAX

102.png

EXAMPLE

103.png

Figure 29.3. COUNT QUERY & OUTPUT

MIN

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

SYNTAX

104.png

EXAMPLE

105.png

Figure 29.4. MIN QUERY & OUTPUT

 
 

MAX 

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

SYNTAX

106.png

EXAMPLE

107.png

Figure 29.5. MAX QUERY & OUTPUT