SQL 05

分組數據

創建分組
如:
Select vend_id ,count(*) as num_prod from products group by vend_id;
過濾分組
Select cust_id ,count() as orders from orders group by cust_id having count() >= 2;

Where和having的區別
Where在分組前過濾數據 having在分組後過濾數據

Select子句順序說明

Select 要返回的列或表達式
From 從中檢索數據的表 僅在表中選擇數據時使用
Where 行級過濾
Group by 分組說明
Having 列級過濾
Order by 輸出排序順序

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章