Having與Where的區別,HavingWhere區別

來源:互聯網
上載者:User

Having與Where的區別,HavingWhere區別

1、where 子句的作用是在對查詢結果進行分組前,將不符合where條件的行去掉,即在分組之前過濾資料,where條件中不能包含聚組函數,使用where條件過濾出特定的行。

2、having 子句的作用是篩選滿足條件的組,即在分組之後過濾資料,條件中經常包含聚組函數,使用having 條件過濾出特定的組,也可以使用多個分組標準進行分組。

 

Demo1:

select 類別, sum(數量) as 數量之和 from Agroup by 類別having sum(數量) > 18


Demo2:(Having和Where的聯合使用方法)

select 類別, SUM(數量)from Awhere 數量 gt;8group by 類別having SUM(數量) gt; 10


附:常見的彙總函式如下   sum(列名)、max(列名)、min(列名)、avg(列名)、count(列名).

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.