用Where子句替换HAVING子句-ORACLE+SQL性能优化(全)

时间:2024-05-15 15:58:35
【文件属性】:

文件名称:用Where子句替换HAVING子句-ORACLE+SQL性能优化(全)

文件大小:2.32MB

文件格式:PPT

更新时间:2024-05-15 15:58:35

SQL

用Where子句替换HAVING子句 避免使用HAVING子句, HAVING 只会在检索出所有记录之后才对结果 集进行过滤. 这个处理需要排序,总计等操作. 如果能通过WHERE子句限 制记录的数目,那就能减少这方面的开销. 例如: 低效: SELECT REGION,AVG(LOG_SIZE) FROM LOCATION GROUP BY REGION HAVING REGION REGION != ‘SYDNEY’ AND REGION != ‘PERTH’ 高效 SELECT REGION,AVG(LOG_SIZE) FROM LOCATION WHERE REGION REGION != ‘SYDNEY’ AND REGION != ‘PERTH’ GROUP BY REGION 顺序 WHERE > GROUP > HAVING


网友评论