How To Apply Filtering Criteria at Group Level?
Page 1 of 1
How To Apply Filtering Criteria at Group Level?
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
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
Similar topics
» Can Group Functions Be Mixed with Non-group Selection Fields?
» What Are Group Functions?
» Can Multiple Columns Be Used in GROUP BY?
» Can Group Functions Be Used in the ORDER BY Clause?
» How To Count Groups Returned with the GROUP BY Clause?
» What Are Group Functions?
» Can Multiple Columns Be Used in GROUP BY?
» Can Group Functions Be Used in the ORDER BY Clause?
» How To Count Groups Returned with the GROUP BY Clause?
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
Sun Jan 31, 2010 12:35 am by Micheal
» Accessing tables of other users in SQL
Sun Jan 31, 2010 12:34 am by Micheal
» Grouping commands in SQL
Sun Jan 31, 2010 12:32 am by Micheal
» Operations on Result Sets in SQL
Sun Jan 31, 2010 12:31 am by Micheal
» Subqueries in SQL
Sun Jan 31, 2010 12:30 am by Micheal
» Joining Relations in SQL
Sun Jan 31, 2010 12:28 am by Micheal
» Delete comand in SQL
Sun Jan 31, 2010 12:27 am by Micheal
» Update command in SQL
Sun Jan 31, 2010 12:26 am by Micheal
» Insert command in SQL
Sun Jan 31, 2010 12:23 am by Micheal