hive 连接(join)查询
1、内连接
hive> select b.*,a.name from userinfo2 b,userinfo a where a.userid=b.userid; hive> select b.*,a.name from userinfo2 b join userinfo a on a.userid=b.userid;
2、外连接
#左联
select b.*,a.name from userinfo2 b left join userinfo a on a.userid=b.userid;
#右联
hive> select a.*,b.name from userinfo b right join userinfo2 a on a.userid=b.userid;
全连接,两边都全显示
hive> select a.*,b.name from userinfo b right join userinfo2 a on a.userid=b.userid;
3、半连接
hive> select * from userinfo2 a where a.userid in (select userid from userinfo); #left semi join必须遵守一个规则:右表(userinfo)只能在on子句里出现,也不能在where子句以及select中出现
hive> select * from userinfo2 a left semi join userinfo b on (a.userid=b.userid);
4、map连接
在之前的内联查询中:
select b.*,a.name from userinfo2 b join userinfo a on a.userid=b.userid;
如果有一个连接表小到可以放入内存,例如userinfo表,hive就可以较小的表放入每个mapper的内存中来执行连接,这就是map连接。 执行这个查询不使用reducer,因此这个查询对right和full join无效,因为只有在对所有输入上进行聚集的步骤(即reduce)才能检测到哪个数据行无法匹配。 map连接可以利用分桶表,需要设置hive.optimize.bucketmapjoin=true
5、子查询,Hive只支持在FROM子句中使用子查询,子查询必须有名字,并且列必须唯一:SELECT ... FROM(subquery) name ...
某些情况子查询可以出现在where子句中,本文中第三点半连接就是子查询,子查询可以出现在where的in或者是exists中。
#子查询的列名必须有唯一的列名。
hive> select year,avg(max_data) from (select year,max(data) as max_data from weather_data group by year) mt group by year;
hive 连接(join)查询的更多相关文章
- hive的join查询
hive的join查询 语法 join_table: table_reference [INNER] JOIN table_factor [join_condition] | table_refere ...
- [Hadoop大数据]——Hive连接JOIN用例详解
SQL里面通常都会用Join来连接两个表,做复杂的关联查询.比如用户表和订单表,能通过join得到某个用户购买的产品:或者某个产品被购买的人群.... Hive也支持这样的操作,而且由于Hive底层运 ...
- Hive学习:Hive连接JOIN用例详解
1 准备数据: 1.1 t_1 01 张三 02 李四 03 王五 04 马六 05 小七 06 二狗 1.2 t_2 01 11 03 33 04 44 06 66 07 77 08 88 1.3 ...
- Hive的join表连接查询的一些注意事项
Hive支持的表连接查询的语法: join_table: table_reference JOIN table_factor [join_condition] | table_reference {L ...
- 《Entity Framework 6 Recipes》中文翻译系列 (19) -----第三章 查询之使用位操作和多属性连接(join)
翻译的初衷以及为什么选择<Entity Framework 6 Recipes>来学习,请看本系列开篇 3-16 过滤中使用位操作 问题 你想在查询的过滤条件中使用位操作. 解决方案 假 ...
- Hibernate中用left join(左外连接)查询映射中没有关联关系的两个表记录问题
一.问题背景 分账表split_summary结构如下: create table SPLIT_SUMMARY ( uuid VARCHAR2(32) not null, star_tdate VAR ...
- (十一) 数据库查询处理之连接(Join)
(十一) 数据库查询处理之连接(Join) 1. 连接操作的一个例子 把外层关系和内层关系中满足一定关系的属性值拼接成一个新的元组 一种现在仍然十分有用的优化思路Late Materializatio ...
- hive:join操作
hive的多表连接,都会转换成多个MR job,每一个MR job在hive中均称为Join阶段.按照join程序最后一个表应该尽量是大表,因为join前一阶段生成的数据会存在于Reducer 的bu ...
- Hive 中Join的专题---Join详解
1.什么是等值连接? 2.hive转换多表join时,如果每个表在join字句中,使用的都是同一个列,该如何处理? 3.LEFT,RIGHT,FULL OUTER连接的作用是什么? 4.LEFT或RI ...
- Hive[6] HiveQL 查询
6.1 SELECT ... FROM 语句 hive> SELECT name,salary FROM employees; --普通查询 hive>SELECT e.n ...
随机推荐
- 搜索引擎ElasticSearch系列(二): ElasticSearch2.4.4 Head插件安装
一:ElasticSearch Head插件简介 elasticsearch-head is a web front end for browsing and interacting with an ...
- linux安装PHP-memcache-redis扩展
1.php memcache 扩展 http://pecl.php.net/package/memcache/3.0.8 下载文件源码 #tar zxvf memcache-3.0.8.tar#/us ...
- Android测试入门学习
一,Android测试新人练习——安装及文件传输 [课前准备] Android测试环境搭建 1.下载并安装JDK: http://www.oracle.com/technetwork/java/jav ...
- Unity ScriptableObject自定义属性显示
1. 继承Editor,重写OnInspectorGUI方法 Editor官方文档 需求 将TestClass中intData属性和stringData按指定格式显示. 实现 定义一个测试类TestC ...
- 观察者模式——Java实例
一.定义 观察者模式(有时又被称为模型-视图(View)模式.源-收听者(Listener)模式或从属者模式)是软件设计模式的一种.观察者模式定义了一种一对多的依赖关系,让多个观察者对象同时监听某一个 ...
- 苹果没放弃手写笔 这样的iPad你想要吗?
12 月 31 日,美国专利与商标局(The U.S. Patent and Trademark Office)当地时间周四批准了一项来自苹果的专利申请,该专利主要描述的是一种可以通过陀螺仪.无线通讯 ...
- visual studio 2010 和 VSS(Visual SourceSafe)的连接使用
visual studio 2010 和 VSS(Visual SourceSafe)的连接使用 1. 在visual vstudio中选择使用VSS插件: 2. 使用VSS进行源码管理: ...
- excel导出功能原型
本篇博客是记录自己实现的excel导出功能原型,下面我将简单介绍本原型: 这是我自制的窗体,有一个ListView和一个Button(导出)控件. 这是我在网上找到了使用exel需要引用的库. usi ...
- c# richBox内容转图片
1.自定义控件,继承richBox public class RichTextBoxPrintCtrl : RichTextBox { //private const double anInch = ...
- KNN算法之图像处理二
1.看了诸多博客,初步得到结论是:KNN不适合做图像分类. 2.如果偏要用此方法进行图像分类,距离计算为:对应的每个像素代表的像素值进行绝对差值计算,最后求和.这就是“图像的距离”