數據庫中where與having的區別


從整體聲明角度分析:

  “where”是一個約束聲明,在查詢數據庫結果返回之前對數據庫的查詢條件做一個約束,即返回結果之前起作用,“where”后面不能跟聚合函數;

  “having”是一個過濾聲明,在查詢數據庫結果返回之后進行過濾,即返回結果之后起作用,“having”后面可以加聚合函數;

聚合函數:是對一組值進行計算,返回單一的值,例如:count(),sum(),max(),min()

從使用角度分析:

  “where”   select  student_id,student_name from student where student_sorce>80;

  "having"  select sum(sorce) from student group by student_sex having student_id<10;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM