SQL tutorial | Interview questions | Oracle
Would you like to react to this message? Create an account in a few clicks or log in to continue.

How To Apply Filtering Criteria at Group Level?

Go down

How To Apply Filtering Criteria at Group Level? Empty How To Apply Filtering Criteria at Group Level?

Post by Micheal Sun Jan 17, 2010 3:06 am

If you want to return only specific groups from the query, you can apply filtering criteria at the
group level by using the HAVING clause inside the GROUP BY clause. The following script gives
you a good HAVING example:
SQL> SELECT department_id, MIN(salary), MAX(salary), AVG(salary)
FROM employees GROUP BY department_id HAVING AVG(salary) < 5000;
DEPARTMENT_ID MIN(SALARY) MAX(SALARY) AVG(SALARY)
------------- ----------- ----------- -----------
30 2500 11000 4150
50 2100 8200 3475.55556
10 4400 4400 4400

Micheal
Admin

Posts : 243
Join date : 2010-01-10

http://sql-tutorial.co.cc

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum