Group By clauses
• It is used to group database tuples on the basis of definite common attribute value like as employees of a department.
Example: Search department number and Number of Employees working in that department.
SELECT DEPTNO, COUNT(EMPNO) FROM EMP
GROUP BY DEPTNO;
Please note that as using group by and aggregate functions the only attributes that can be put in select clause are the aggregated functions and the attributes that have been used for grouping the information. For instance, in the example 20, we cannot put ENAME attribute in the SELECT clause as it will not have a distinct value for the group. Please note the group here is formed on DEPTNO.