Hive中的CATS和WITH(保姆级案例)

CTAS – as select方式建表:

create temporary table tmp_employee as select name,work_place from employee;

WITH:

create table if not exists employee(
	name string,
	work_place array<string>,
	gender_age struct<gender:string,age:int>,
	skills_score map<string,int>,
	depart_title map<string,array<string>>
)
comment 'this is an internal table'
row format delimited fields terminated by '|'
collection items terminated by ','
map keys terminated by ':'
lines terminated by '\n';

例:查询所有名字是Will性别是Male的人和所有性别是Female的人。

方式一:select t.* from(select * from employee where gender_age.gender='Male') as t where t.name = 'Will' union all select * from employee where gender_age.gender ='Female;'
请添加图片描述

方式二:
with
t1 as (select * from employee where gender_age.gender = 'Male'),
t2 as (select * from t1 where t1.name = 'Will'),
t3 as (select * from employee where gender_age.gender = 'Female')
select * from t2 union all select * from t3;
请添加图片描述
可以看到这两种方式的结果是一样的,但是方法二的可读性更高。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

万家林

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值