|
GROUP BY
Group By clause is used to group the tuples with respect to a attribute.
Syntax ::
[SELECT] <COLUMN1>....<COLUMNX>
FROM <TABLE>
WHERE <CONDITION>
GROUP BY <COLUMNS>
[HAVING <GROUP_CONDITION>];
Example 1::
SELECT CUST_DEPTNO, MIN(CUST_SAL), MAX(CUST_SAL)
FROM EMP
GROUP BY CUST_DEPTNO;
|
Example 2::
SELECT CUST_DEPTNO, MIN(CUST_SAL), MAX(CUST_SAL)
FROM EMP
WHERE CUST_JOB=' MANAGER'
GROUP BY CUST_DEPTNO
HAVING COUNT(*)>5 ;
|
Above query processed in this way ::
1. Select the tuples which meets the WHERE clause condition
2. It forms groups according to the GROUP BY clause
3. Now AGGREGATE functions applied to each group.
4. Displayed the values for columns and aggregations which are in teh SELECTED clause
|