How To Apply Filtering Criteria at Group Level in Oracle?
Submitted by: AdministratorIf 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),
2 AVG(salary) FROM employees GROUP BY department_id
3 HAVING AVG(salary) < 5000;
<pre>DEPARTMENT_ID MIN(SALARY) MAX(SALARY) AVG(SALARY)
------------- ----------- ----------- -----------
30 2500 11000 4150
50 2100 8200 3475.55556
10 4400 4400 4400</pre>
Submitted by: Administrator
SQL> SELECT department_id, MIN(salary), MAX(salary),
2 AVG(salary) FROM employees GROUP BY department_id
3 HAVING AVG(salary) < 5000;
<pre>DEPARTMENT_ID MIN(SALARY) MAX(SALARY) AVG(SALARY)
------------- ----------- ----------- -----------
30 2500 11000 4150
50 2100 8200 3475.55556
10 4400 4400 4400</pre>
Submitted by: Administrator
Read Online Oracle Database Job Interview Questions And Answers
Top Oracle Database Questions
☺ | How Much Memory Your 10g XE Server Is Using? |
☺ | How To Use "OUT" Parameter Properly? |
☺ | How Run SQL*Plus Commands That Are Stored in a Local File? |
☺ | What Is the Relation of a User Account and a Schema? |
☺ | What Happens to Indexes If You Drop a Table? |
Top DB Oracle Categories
☺ | Oracle PL-SQL Interview Questions. |
☺ | Oracle DBA Interview Questions. |
☺ | Oracle D2K Interview Questions. |
☺ | OCI Interview Questions. |
☺ | Oracle RMAN Interview Questions. |