oracle Where clause HAVING clause is replaced with

Avoid using the HAVING clause, HAVING only filter the result set after the fishes retrieve all records. This process requires a sort, total and so on. If you can use a WHERE clause to limit the number of records that can reduce this overhead .

 E.g:

     Inefficient:

     SELECT REGION,AVG(LOG_SIZE)

     FROM LOCATION

     GROUP BY REGION

     HAVING REGION REGION != ‘SYDNEY’

     AND REGION != ‘PERTH’

      Efficient

     SELECT REGION,AVG(LOG_SIZE)

     FROM LOCATION

     WHERE REGION REGION != ‘SYDNEY’

     AND REGION != ‘PERTH’

     GROUP BY REGION

(  The HAVING The conditions for some of the more general set of functions , such as COUNT () and the like . Besides , the general conditions should be written in the WHERE clause )

Guess you like

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