別忘記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結果:性能

相關文章
相關標籤/搜索