0% found this document useful (0 votes)
20 views

Practical No 8 Group Function

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Practical No 8 Group Function

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Practical No.

11
Group Function
Group functions are built-in SQL functions that operate on groups of rows and return one value for the entire
group. These functions are: COUNT, MAX, MIN, AVG, SUM, DISTINCT

SQL COUNT (): This function returns the number of rows in the table that satisfies the condition specified in
the WHERE condition.

For Example: If you want the number of employees in a particular department, the query would be:

SELECT COUNT (*) FROM employee

WHERE dept = 'Electronics';


SQL DISTINCT (): This function is used to select the distinct rows.

For Example: If you want to select all distinct department names from employee table, the query would
be:

SELECT DISTINCT dept FROM employee;

To get the count of employees with unique name, the query would be:

SELECT COUNT (DISTINCT name) FROM employee;


SQL MAX (): This function is used to get the maximum value from a column.
To get the maximum salary drawn by an employee, the query would be:

SELECT MAX (salary) FROM employee;


SQL MIN (): This function is used to get the minimum value from a column.
To get the minimum salary drawn by an employee, he query would be:

SELECT MIN (salary) FROM employee;

SQL AVG (): This function is used to get the average value of a numeric column.
To get the average salary, the query would be

SELECT AVG (salary) FROM employee;

SQL SUM (): This function is used to get the sum of a numeric column
To get the total salary given out to the employees,
SELECT SUM (salary) FROM employee;

Group By, Having Clause


The GROUP BY clause is a SQL command that is used to group rows that have the
same values.

GROUP BY Syntax
Now that we know what the GROUP By clause is, let's look at the syntax for a basic
group by query.
SELECT statements... GROUP BY column_name1 [, column_name2...] [HAVING condition];

 "SELECT statements..." is the standard SQL SELECT command query.


 "GROUP BY column_name1" is the clause that performs the grouping based
on column_name1.
 "[, column_name2...]" is optional; represents other column names when the
grouping is done on more than one column.
 "[HAVING condition]" is optional; it is used to restrict the rows affected by
the GROUP BY clause. It is similar to the WHERE clause.

Join & Types


JOIN
A JOIN clause is used to combine rows from two or more tables, based on a related column between
them.

Types
 (INNER) JOIN: Returns records that have matching values in both tables
 LEFT (OUTER) JOIN: Returns all records from the left table, and the matched records
from the right table
 RIGHT (OUTER) JOIN: Returns all records from the right table, and the matched records
from the left table
 FULL (OUTER) JOIN: Returns all records when there is a match in either left or right table

You might also like