oracle GROUP BY Optimization

GROUP BY statement to improve efficiency, you can filter out unwanted records before the GROUP BY. The following two queries return the same result but the second obviously on a lot faster.

Inefficient:

   SELECT JOB , AVG(SAL)

   FROM EMP

   GROUP JOB

   HAVING JOB = ‘PRESIDENT’

   OR JOB = ‘MANAGER’

 Efficient:

   SELECT JOB , AVG(SAL)

   FROM EMP

   WHERE JOB = ‘PRESIDENT’

   OR JOB = ‘MANAGER’

   GROUP JOB

Guess you like

Origin www.cnblogs.com/fanweisheng/p/11125608.html