当选择两个字段时,例如:"select XX1, XX2 from tb; ",那么将distinct放在前一个字段XX1之前和放在后一个字段XX2之前,结果有什么不同呢?

先说结论:如果将distinct放在前一个字段之前,则会返回对两个字段的组合去重后的结果;而如果将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)选择两个字段时,distinct放在后一个字段之前:

select id, distinct content
from tmp_tb;

结果出现错误提示:

FAILED: ParseException line 1:11 cannot recognize input near'distinct' 'content' 'from' in selection target

4)选择两个字段时,distinct放在前一个字段之前:

select distinct id, content
from tmp_tb;

结果如下:

1       5

2       5

2       6

3       6

可见,当选择两个字段时,如果将distinct放在前一个字段之前,则会返回对两个字段的组合去重后的结果,即distinct同时作用于两个字段;而如果将distinct放在后一个字段之前,则有语法错误。

HIVE点滴:选择两个字段时distinct位置的影响的更多相关文章

  1. 选择两个字段时distinct位置的影响

    当选择两个字段时,例如:"select XX1, XX2 from tb; ",那么将distinct放在前一个字段XX1之前和放在后一个字段XX2之前,结果有什么不同呢? 先说结 ...

  2. update更新两个字段

    update更新两个字段时的sql语句: update tj_record set is_recycle_reprint_guide='1' , recycle__guide_date=now() w ...

  3. 1) 上传多张图片时 ,对 $_FILES 的处理. upload ; 2)fileinput 上传多张图片. 3) 修改,删除的时候删除原来的资源,图片 update, delete , 删除 4)生成器中两个字段上传图片的时候,要修改生成器生成的代码

    1上传多张图片, 要对 $_FILES进行 重新处理. //添加 public function addCourseAlbumAction() { $CourseAlbumModel = new Co ...

  4. django ORM model filter 条件过滤,及多表连接查询、反向查询,某字段的distinct

    版权归作者所有,任何形式转载请联系作者.作者:petanne(来自豆瓣)来源:https://www.douban.com/note/301166150/ 1.多表连接查询:感觉django太NX了. ...

  5. 让hive的表注释和字段注释支持中文

    此处用的数据库类型为mysql.发现hive在初始化创建这些表的时候,大部分字段的字符集给设置成了latin1,然后collation设成了latin1_bin. 但是我们在hive中创建表时,表注释 ...

  6. python django model filter 条件过滤,及多表连接查询、反向查询,某字段的distinct[转]

    1.多表连接查询:当我知道这点的时候顿时觉得django太NX了.   class A(models.Model):     name = models.CharField(u'名称')   clas ...

  7. sqoop 从oracle导数据到hive中,date型数据时分秒截断问题

    oracle数据库中Date类型倒入到hive中出现时分秒截断问题解决方案 1.问题描述: 用sqoop将oracle数据表倒入到hive中,oracle中Date型数据会出现时分秒截断问题,只保留了 ...

  8. django model filter 条件过滤,及多表连接查询、反向查询,某字段的distinct

    1.多表连接查询:当我知道这点的时候顿时觉得django太NX了.  class A(models.Model):    name = models.CharField(u'名称')  class B ...

  9. mysql的if用法解决同一张数据表里面两个字段是否相等统计数据量。

    MySQL的使用用法如下所示:格式:if(Condition,A,B)意义:当Condition为true时,返回A:当Condition为false时,返回B.作用:作为条件语句使用.mysql的i ...

随机推荐

  1. [Fiddler] ReadResponse() failed: The server did not return a complete response for this request. Server returned 0 bytes.

    待解决 [Fiddler] ReadResponse() failed: The server did not return a complete response for this request. ...

  2. [python] 查找列表中重复的元素

    a = [1, 2, 3, 2, 1, 5, 6, 5, 5, 5] b = set(a) for each_b in b: count = 0 for each_a in a: if each_b ...

  3. spring boot(九)定时任务

    在我们的项目开发过程中,经常需要定时任务来帮助我们来做一些内容,springboot默认已经帮我们实行了,只需要添加相应的注解就可以实现 1.pom包配置 pom包里面只需要引入springboot ...

  4. consul总结

    一.介绍 内置了服务注册与发现框 架.分布一致性协议实现.健康检查.Key/Value存储.多数据中心方案,不再需要依赖其他工具(比如ZooKeeper等)服务部署简单,只有一个可运行的二进制的包.每 ...

  5. 【IDEA】【2】创建Maven项目及部署发布

    正文: 1,我参考的文档1已经比较全面了,需要注意的是界面可能有点不一样,有些地方需要自己注意一下 2,project和model的概念:挺困扰人的,我目前没有多模块开发,开发多个项目的时候是开了多个 ...

  6. vue3.0 配置公共请求地址

    正常请求接口: return request({ url: 'http://192.168.1.0/User/cancelUpgrade', method: 'get', params: data } ...

  7. Python Microsoft Visual C++ 10.0 is required (Unable to find vcvarsall.bat)

    在windows 平台下,当python使用以下方式安装时,可能出现以下错误: > python setup.py install error: Microsoft Visual C++ 10. ...

  8. PAT 1027 Colors in Mars

    1027 Colors in Mars (20 分)   People in Mars represent the colors in their computers in a similar way ...

  9. sparklyr-R语言访问Spark的另外一种方法

    Connect to Spark from R. The sparklyr package provides a complete dplyr backend. Filter and aggregat ...

  10. python零碎知识点

    0.规范化 使用Ctrl+Alt+L可以将代码排列格式更加规范化 1.浮点数 1.23x109就是1.23e9或者12.3e8:0.000012可以写成1.2e-5 2.字符串 >>> ...