分組數據

1 介紹

分組返回數據,不是where的那種返回特定數據sql

2 建立分組(group by)

select vend_id, count(*) as num_prods from products group by vend_id;

uWfcxP.png

2.1 分析

按vend_id字段分組,而後統計總數返回數據spa

3 過濾分組(having)

select cust_id, count(*) as orders 
from orders
group by cust_id
having count(*) >= 2;

uW4VXV.png

3.1 分析

篩選出須要數據code

3.2 where和having 區別

where過濾行,having過濾分組blog

相關文章
相關標籤/搜索