hive 可以通过with查询来提高查询性能,因为先通过with语法将数据查询到内存,然后后面其它查询可以直接使用,这种方法与创建临时表类似但是不需要创建临时表实体表,内存中的子查询结果在会话结束后会自动删除。
with q1
as (
select key from src
where key = '5')
select *
from q1;
-- from style
with q1
as (
select * from src
where key= '5')
from q1
select *;
-- chaining CTEs
with q1
as (
select key from q2
where key = '5'),
q2 as (
select key from src
where key = '5')
select * from (
select key from q1) a;
-- union example
with q1
as (
select * from src
where key= '5'),
q2 as (
select * from src s2
where key = '4')
select * from q1
union all select * from q2;
转载于:https://www.cnblogs.com/shujuxiong/p/9910052.html