避免使用HAVING子句,因为它只在检索所有记录之后才进行结果集过滤,需要排序和总计等操作。通过WHERE子句限制记录数目可以减少这些开销。例如:非效率的写法如下:SELECT REGION,AVG(LOG_SIZE) FROM LOCATION GROUP BY REGION HAVING REGION != ‘SYDNEY’ AND REGION != ‘PERTH’;而效率更高的写法是:SELECT REGION,AVG(LOG_SIZE) FROM LOCATION WHERE REGION != ‘SYDNEY’ AND REGION != ‘PERTH’ GROUP BY REGION。