distinct 和 group by 使用对比
来源:互联网 发布:linux上snmp配置 编辑:程序博客网 时间:2024/06/05 14:59
t3表的结构如下:
Select * FROM t3
id edu age
1 本 20
2 本 25
3 本 30
4 本 30
5 本 25
6 中 15
7 中 20
8 中 20
9 专 20
10 专 20
11 专 20
12 专 30
13 专 30
--------------------------------------
Select distinct edu,age
FROM t3
order by age
edu age
中 15
本 20
中 20
专 20
本 25
本 30
专 30
小结:1、distinct edu,age 是将edu,age两个字段看成一体,只要edu,age这两个字段相同,
就将其视为重复记录;
2、在Select中只能用一次distinct或all;
3、在Select中用了distinct就不能用ALL;用了ALL就不能用distinct;不能同时存在;
4、如果指定了SELECT DISTINCT,那么ORDER BY 子句中的项就必须出现在选择列表中;
---------------------------------------
select edu,age,count(*) as '人数'
--into
from t3
--where id<10
--where 分组前记录的过滤条件
group by edu,age
--having 分组后对组的过滤条件
order by age
edu age 人数
中 15 1
本 20 1
中 20 2
专 20 3
本 25 2
本 30 2
专 30 2
小结:1、distinct edu,age 是将edu,age两个字段看成一体,只要edu,age这两个字段相同,
就将其视为同组;
2、SELECT子句中的列名必须为分组列或列函数;
3、where子句中的列名可以为表中任意字段;
4、having子句中的列名必须为分组列或列函数;
- distinct 和 group by 使用对比
- distinct 和 group by 使用对比
- DISTINCT和GROUP BY
- distinct和group by
- distinct和group by
- HIVE group by 和count(distinct)进行对比
- DB2数据库DISTINCT与GROUP BY 对比
- mysql:distinct与group by 效率对比
- mysql distinct 和 group by
- MY SQL使用GROUP BY 和 DISTINCT哪个会更快????
- MySQL 里面的Where 和Having和Count 和distinct和Group By对比
- Hive中distinct和Group by效率对比及处理方式
- [转]DataTable 使用 Distinct/group by/
- DISTINCT和GROUP BY的区别
- Distinct 和Group by的区别
- DISTINCT和GROUP BY的区别
- SQL中的Distinct和Group By
- DISTINCT和GROUP BY的效率
- 微软研究院Detour开发包之API拦截技术
- Scott Mitchell 的ASP.NET 2.0数据教程之一: 创建一个数据访问层
- 昨天的题目搞定
- 第一篇文章
- 今日感慨:鲜花大多插牛粪
- distinct 和 group by 使用对比
- Linux之CORE文件
- asp.net中保持状态的方法
- SQLite cominbed source file splitter
- SQL Server 2005 导入和导出向导
- (转)几个Java的开源爬虫
- Wget使用說明
- Scott Mitchell 的ASP.NET 2.0数据教程之二:创建一个业务逻辑层
- Google maps及51ditu的图片切割及存储方法