|
HAVING
HAVING clause is used to retreive the grouping tuples which satisfies the condition.HAVING caluse is used with the GROUP BY clause.
Syntax ::
[SELECT] <COLUMN1>....<COLUMNX>
FROM <TABLE>
WHERE <CONDITION>
GROUP BY <COLUMNS>
HAVING <GROUP_CONDITION>;
Example ::
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. Discards all the groups which does not meet the HAVING condition
4. Now AGGREGATE functions applied to each group.
5. Displayed the values for columns and aggregations which are in teh SELECTED clause
|