首页 > 其他 > 详细

分组数据

时间:2019-10-12 09:24:04      阅读:65      评论:0      收藏:0      [点我收藏+]

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过滤分组

分组数据

原文:https://www.cnblogs.com/chenzhuantou/p/11658191.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!