避免使用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。