Oracle's query - grouping queries

- check out the average salary for each department of 
the SELECT e.deptno, AVG (e.sal)
 from emp E
 Group  by e.deptno;

Grouping query, in the group by the back of the original columns, select to appear in the back

Does not appear in the group by the original column behind, it appears like must be added to the aggregate function in the select behind


 

 

- check out the average wage higher than 2000 departments 
the SELECT e.deptno, AVG (e.sal)
 from emp E
 Group  by e.deptno
 the HAVING  AVG (e.sal) > 2000 ;

All conditions can not be used to determine an alias

 

where the data packet before filtration, having a filtered data packet

where necessary before group by, having in the group by following


 

 

- check out every sector wages higher than the average wage of employees 800 
- then check out the average salary higher than 2000 departments 
the SELECT e.deptno, AVG (e.sal)
 from emp E
 the WHERE e.sal > 800 
Group  by e.deptno
 the HAVING  AVG (e.sal) > 2000 ;

 

Guess you like

Origin www.cnblogs.com/Sm1lence/p/11426755.html