别忘记having子句

做用:在 SQL 中增长 HAVING 子句缘由是,WHERE 关键字没法与统计函数一块儿使用。sql

以下查询功能可用having子句
ide

  
  
  
  
  1. select company, count(employee) cnt 
  2. from works t 
  3. where salary>5000 
  4. group by company 
  5. having cnt>1 

与使用中间表SQL相比性能差异巨大:函数

  
  
  
  
  1. select company
  2. from (select company, count(employee) cnt from works where salary>5000 group by company) t  
  3. where cnt>1 

使用MySQL Workbanch 的Explain结果:性能

相关文章
相关标签/搜索