SQL Group Function

In SQL, SQL Group function that is used to operate in Group data. Group Functions many arguments and produce only one result.

 

Group Function in SQL operates on sets of rows to give one result per Row.

Group Functions in SQL are –

  • Count

  • AVG

  • MAX

  • MIN

  • SUM

  • DISTINCT

 

SQL Group Function with Example

SQL COUNT()

This function returns the number of rows in the table that satisfies the condition specified in the WHERE condition. If the WHERE condition is not specified, then the query returns the total number of rows in the table.

Query – Calculate the total number of employees in Employee table.

SQL> Select count(*) from Employees;

 

SQL DISTINCT()

This function is used to select the distinct rows (Remove duplicate Rows).

Query – Find all departments from Employees Table.

SQL> Select Distinct(Department_Id) from Employees;

 

SQL MAX()

This function is used to get the maximum value from a column.

Query – Find max salary drawn by an Employee.

SQL> Select Max(Salary) from Employees;

SQL MIN()

This function is used to get the minimum value from a column.

Query – Find minimum salary drawn by an Employee.

SQL> Select Min(Salary) from Employees;

 

SQL AVG()

This function is used to get the average value of a numeric column.

Query – Find average Salary of your employees.

SQL> Select Avg(Salary) from Employees;

 

SQL SUM()

This function is used to get the sum of a numeric column.

Query – Find total Salary given to employees.

SQL> Select Sum(Salary) from Employees;

0 Comment

Leave a Reply