避免使用HAVING子句,因为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。