1 介紹
分組返回?cái)?shù)據(jù),不是where的那種返回特定數(shù)據(jù)
2 創(chuàng)建分組(group by)
select vend_id, count(*) as num_prods from products group by vend_id;
2.1 分析
按vend_id字段分組悠鞍,然后統(tǒng)計(jì)總數(shù)返回?cái)?shù)據(jù)
3 過(guò)濾分組(having)
select cust_id, count(*) as orders
from orders
group by cust_id
having count(*) >= 2;
3.1 分析
篩選出需要數(shù)據(jù)
3.2 where和having 區(qū)別
where過(guò)濾行慷彤,having過(guò)濾分組