HAVING 子句
在 SQL 中增加 HAVING 子句原因是,WHERE 關鍵字無法與合計函數一起使用。
where只能篩選源數據字段,having多與group by 一起使用,並且條件常常是聚集函數;
當有group by 時,having在group by 條件的後面,而where 在group by的前面。
先對錶數據進行where過濾,再對分組數據進行having過濾。
select grade ,sum(score) from a_info a group by grade having sum(score) >200;
查詢每個年級總分數大於200的