1 介绍

分组返回数据,不是where的那种返回特定数据

2 创建分组(group by)

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

分组数据

2.1 分析

按vend_id字段分组,然后统计总数返回数据

3 过滤分组(having)

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

分组数据

3.1 分析

筛选出需要数据

3.2 where和having 区别

where过滤行,having过滤分组

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-22
  • 2021-10-23
猜你喜欢
  • 2021-05-07
  • 2021-05-10
  • 2022-12-23
  • 2021-11-13
  • 2021-06-19
  • 2021-11-30
  • 2022-12-23
相关资源
相似解决方案