sqle icon indicating copy to clipboard operation
sqle copied to clipboard

新增MySQL规则 "建议将 having 里面的平直字段移到where中"

Open sjjian opened this issue 3 years ago • 0 comments

Database Type

MySQL

Rule Description

建议将 having 里面的平直字段移到where中

Why

避免使用HAVING字句筛选非聚合字段,因为HAVING只会在检索出所有记录之后才对结果集进行过滤,而where则是在聚合前刷选记录,如果能通过where字句限制记录的数目,那就能减少这方面的开销。HAVING中的条件一般用于聚合函数的过滤,除此之外,应该将条件写在where字句中

sjjian avatar Oct 31 '22 10:10 sjjian