栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

hive with as的测试使用记录

hive with as的测试使用记录

目的:在做一些sql的测试过程中,需要建相应的临时表支持测试。
with as 可以快速支持相关临时表建设工作。
with table1 as
(
select 1 as t1_id, ‘小满t1_1’ as name, 100 as old
union all
select 2 as t1_id, ‘小满t1_2’ as name, 100 as old
union all
select 3 as t1_id, ‘小满t1_3’ as name, 100 as old
union all
select 4 as t1_id, ‘小满t1_4’ as name, 100 as old
),
table2 as(
select 1 as t1_id, ‘小满t2_1’ as name, 100 as old
union all
select 2 as t1_id, ‘小满t2_2’ as name, 100 as old
union all
select 3 as t1_id, ‘小满t2_3’ as name, 100 as old
union all
select 5 as t1_id, ‘小满t2_5’ as name, 100 as old
),
table3 as(
select 1 as t1_id, ‘小满t3_1’ as name, 100 as old
union all
select 2 as t1_id, ‘小满t3_2’ as name, 100 as old
union all
select 4 as t1_id, ‘小满t3_4’ as name, 100 as old
union all
select 6 as t1_id, ‘小满t3_6’ as name, 100 as old
)

例如在测试:left join 过程发现 on 中条件不同,即结果也不同。
即 :

select * from table1 t1
left join table2 t2
on t1.t1_id=t2.t1_id
LEFT JOIN table3 t3
on t1.t1_id=t3.t1_id
结果不同于
select * from table1 t1
left join table2 t2
on t1.t1_id=t2.t1_id
LEFT JOIN table3 t3
on t2.t1_id=t3.t1_id
结果不同于
select * from table1 t1
left join table2 t2
on t1.t1_id=t2.t1_id
LEFT JOIN table3 t3
on t1.t1_id=t3.t1_id
and t1.old=t3.old

记住hive 多个left join 怎么执行 原则:
eg:
select * from a left join b on a.abid = b.baid left join c on c.cbid = b.bcid
顺序是先a,b组合成一个虚拟表,然后虚拟表再和C表关联

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/688436.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号