大数据课程F4——HIve的其他操作

文章作者邮箱:[email protected]              地址:广东惠州

 ▲ 本章节目的

⚪ 掌握HIve的join;

⚪ 掌握HIve的查询和排序

⚪ 掌握HIve的beeline

⚪ 掌握HIve的文件格式

⚪ 掌握HIve的基本架构

⚪ 掌握HIve的优化;

一、join

1. 概述

1. 在Hive中,同MySQL一样,提供了多表的连接查询,并且支持left join,right join,inner join,full outer join以及笛卡尔积查询。

2. 在连接查询的时候,如果不指定,那么默认使用的是inner join。

3. 在Hive中,除了支持上述比较常用的join以外,还支持left semi join。当a left semi join b的时候,表示获取a表中的数据哪些在b表中出现过。

2. 案例:

#建表语句

create external table orders (orderid int, orderdate string, productid int, num int) row format delimited fields terminated by ' 'location '/orders';

create external table products (productid int, name string, price double) row format delimited fields terminated by ' ' location '/products';

#左连接 - 以左表为准

select * from orders o left join products p on o.productid = p.productid;

#右连接 - 以右表为准

select * from orders o right join products p on o.productid = p.productid;

#内连接 - 获取两个表都有的数据

select * from orders o inner join products p on o.productid = p.productid;

#全外连接

select * from orders o full outer join products p on o.productid = p.productid;

#笛卡尔积

select * from orders, products;

#需求一:获取每一天卖了多少钱

select o.orderdate, sum(o.num * p.price) from orders o inner join products p on o.productid = p.productid group by o.orderdate;

#需求二:查询哪些商品被卖出去过 - 实际上就是获取商品表中的哪些数据在订单表中出现过

select * from products p left semi join orders o on p.productid = o.productid;

二、查询和排序

1. having

1. 在Hive中,where可以针对字段来进行条件查询,但是where无法针对聚合结果进行条件查询;如果需要对聚合结果进行条件查询,那么此时需要使用having。

2. 案例:

#

猜你喜欢

转载自blog.csdn.net/u013955758/article/details/132032184
F4