SELECT command with Aggregate Function:

SQL provides some aggregate function which is used in database. It is predefined which available by SQL server. SQL aggregate functions return a single value, calculated from values in a column.  There are lots of aggregate functions in SQL server in which some are briefly described below:

SELECT command with AVG () function:

AVG () function are widely used to calculate the average of column value that is The AVG () function returns the average value of a numeric column.

Syntax:

SELECT AVG [SPECIFIED_COLUMN_NAME] FROM <TABLE_NAME>

Example:
                ---- CALCULATE AVERAGE OF SALARY IN DATABASE TABLE STUDENT_MARKS
SELECT AVG(SALARY) AS AVERAGE FROM STUDENT_MARKS

‘SELECT’ command with Aggregate Function

SELECT command with SUM () function:

SUM () aggregate function returns sum of all column value.

Syntax:

SELECT SUM ([SPECIFIED_COLUMN_NAME]) FROM <TABLE_NAME>

Example:
---- CALCULATE SUM OF ALL VALUE SALARY COLUMN 
SELECT SUM(SALARY) AS SUMSALARY FROM STUDENT_MARKS

‘SELECT’ command with Aggregate Function

SELECT command with COUNT () function:

Count () aggregate function returns number of rows either specified any column name or whole table.

Syntax:

SELECT COUNT ([SPECIFIED_COLUMN_NAME] | [ALL]) FROM <TABLE_NAME>

Example:
--- COUNT THE NUMBER OF ROWS IN STUDENT_MARKS TABLE
SELECT COUNT(*) FROM STUDENT_MARKS


‘SELECT’ command with Aggregate Function

SELECT command with MAX () function:

Max () function returns maximum value of column.

Syntax:

SELECT MAX ([SPECIFIED_COLUMN_NAME]) FROM <TABLE_NAME>

Example:
--- CALCULATE MAX VALUE OF COLUMN USING MAX FUNCTION
SELECT MAX(SALARY) FROM STUDENT_MARKS


‘SELECT’ command with Aggregate Function

SELECT command with MIN () function:

MIN () function returns the minimum value of column of table.

Syntax:

SELECT MAX ([SPECIFIED_COLUMN_NAME]) FROM <TABLE_NAME>

Example:
--- CALCULATE MIN VALUE OF COLUMN USING MIN FUNCTION
SELECT MIN(SALARY) FROM STUDENT_MARKS


‘SELECT’ command with Aggregate Function

 

 

  Modified On Mar-22-2018 05:58:20 AM

Leave Comment