HIVE点滴:group by和distinct语句的执行顺序
同一条语句之中,如果同时有group by和distinct语句,是先group by后distinct,还是先distinct后group by呢?
先说结论:先group by后distinct。
以下是在HIVE中的验证:
1)建表:其中xxx替换为本地目录名
create external table tmp_tb(
id int,
content int
) row format delimited
fields terminated by ','
stored as textfile
location '/tmp/xxx';
2)从tmp_tb文件中导入数据
load data
local inpath '/home/xxx/tmp_tb'
overwrite into table tmp_tb;
tmp_tb内容:
1,5
2,6
2,5
2,5
3,6
3)仅有group by时:
select id, count(content)
from tmp_tb
group by id;
结果如下:
1 1
2 3
3 1
4)同时有group by和distinct时:
select id, count(distinct content)
from tmp_tb
group by id;
结果如下:
1 1
2 2
3 1
可见,同时有group by和distinct时,显然是先group by 后distinct。如果是先distinct,后group by,则结果应该只有两条记录,因为content只有5和6两种数值。
HIVE点滴:group by和distinct语句的执行顺序的更多相关文章
- group by和distinct语句的执行顺序
同一条语句之中,如果同时有group by和distinct语句,是先group by后distinct,还是先distinct后group by呢? 先说结论:先group by后distinct. ...
- 查询语句中select from where group by having order by的执行顺序
查询语句中select from where group by having order by的执行顺序 1.查询中用到的关键词主要包含六个,并且他们的顺序依次为 select--from--w ...
- 深入理解group by 语句的执行顺序 from→where→group by→select(含聚合函数)
由于之前没有对group by 语句的执行顺序(执行原理)做深入的了解,所以导致在实际应用过程中出现了一些问题.举个简单的粟子,比如一个表testA中的所有数据如下图: 我现在想从testA中查询us ...
- SQLServer2005中查询语句的执行顺序
SQLServer2005中查询语句的执行顺序 --1.from--2.on--3.outer(join)--4.where--5.group by--6.cube|rollup--7.havin ...
- 容易被忽略的事----sql语句中select语句的执行顺序
关于Sql中Select语句的执行顺序,一直很少注意这个问题,对于关键字的使用也很随意,至于效率问题,因为表中的数据量都不是很大,所以也不是很在意. 今天在一次面试的时候自己见到了,感觉没一点的印象, ...
- SQL语句的执行顺序
一.sql语句的执行顺序 (8)SELECT (9) DISTINCT (11) <TOP_specification> <select_list> (1) FROM < ...
- 浅谈SQL优化入门:1、SQL查询语句的执行顺序
1.SQL查询语句的执行顺序 (7) SELECT (8) DISTINCT <select_list> (1) FROM <left_table> (3) <join_ ...
- SQL SERVER 一个SQL语句的执行顺序
一个SQL 语句的执行顺序 1.From (告诉程序 来自哪张表 如果是表表达式 依旧是如此顺序) 2.Where(条件筛选 谓词筛选 ) 3.Group by(分组) 4.Having(分组 ...
- {MySQL的逻辑查询语句的执行顺序}一 SELECT语句关键字的定义顺序 二 SELECT语句关键字的执行顺序 三 准备表和数据 四 准备SQL逻辑查询测试语句 五 执行顺序分析
MySQL的逻辑查询语句的执行顺序 阅读目录 一 SELECT语句关键字的定义顺序 二 SELECT语句关键字的执行顺序 三 准备表和数据 四 准备SQL逻辑查询测试语句 五 执行顺序分析 一 SEL ...
随机推荐
- 378. Kth Smallest Element in a Sorted Matrix(java,优先队列)
题目: Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the ...
- npm常用功能
1. npm -v在命令行中输入该代码,可以查看npm当前版本号 2.安装依赖包2.1 npm install <name>先使用cd命令跳转到需要安装模块的目录,在该目录下执行np ...
- System.gc()和-XX:+DisableExplicitGC启动参数,以及DirectByteBuffer的内存释放
首先我们修改下JVM的启动参数,重新运行之前博客中的代码.JVM启动参数和测试代码如下: -verbose:gc -XX:+PrintGCDetails -XX:+DisableExplicitGC ...
- Oracle中如何查询一个表的所有字段名和数据类型
Oracle中如何查询一个表的所有字段名和数据类型 查询语法 select A.COLUMN_NAME,A.DATA_TYPE from user_tab_columns A where TABLE_ ...
- 【Java算法】输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数
import java.util.Scanner; public class CountZimuShuzi { public static void main(String[] args) { Sys ...
- linux的典型分支:
1.redhat 2.debian 3.centOS 4.ubuntu 5.fedora 6.kali linux
- ueditor自定义额外参数
<script>ue.ready(function () { ue.setContent('123456');//设置富文本编辑器初始化数据 ue.execCommand('serverp ...
- windows 路由的配置
查看ip路由表 route print : netstat -r windows 下添加一条路由 route命令 route [-f][-p][command [distinataion] [MASK ...
- .NetCore发布到Centos docker
将.netcore mvc项目发布到centos7的docker中.环境 vmware14+Centos7+docker-ce 1.使用vs将.netcoremvc项目发布到本地,修改发布后的目录 名 ...
- JavaScript -基础- 函数与对象(二)String
一.判断数据类型typeof与判断对象类型instanceof 1.typeof typeof只能判断基础数据类型,无法判断引用数据类型 <script> var s="hell ...