分组数据

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

相关文章
相关标签/搜索