Hive 连接 CTE
有人可以帮我在下面的查询中添加注释的连接条件吗?如果我执行这个查询工作正常,但是当我尝试添加一个在下面的查询中注释的连接条件时,它无法访问列 high_V2 并给出列/表 alisa 未找到问题。
with MYTABLE as (
select
T1.LOW_V2 as LOW_V2,
T2.LOW_V as LOW_V,
T2.HIGH_V as HIGH_V
from TAB1 T1
inner join
TAB2 T2
on
T1.LOW_V2=T2.LOW_V
-- and high_V2=T2.HIGH_V
)
select lpad(concat(splitted[0],translate(splitted[1],'0','9')),18,0) as high_V2,
LOW_V2,LOW_V,HIGH_V from
(
select split(regexp_replace(LOW_V2,'(\\d*?)(0+)$','$1|$2'),'\\|') splitted,
LOW_V2,
LOW_V,HIGH_V
from MYTABLE )s;
Can someone help me to add the commented Join Condition in the below query. If I am executing this query is working fine but when I am trying to add one more join codition which is commented in the below query its not able to access the column high_V2 and giving column/table alisa not found issue.
with MYTABLE as (
select
T1.LOW_V2 as LOW_V2,
T2.LOW_V as LOW_V,
T2.HIGH_V as HIGH_V
from TAB1 T1
inner join
TAB2 T2
on
T1.LOW_V2=T2.LOW_V
-- and high_V2=T2.HIGH_V
)
select lpad(concat(splitted[0],translate(splitted[1],'0','9')),18,0) as high_V2,
LOW_V2,LOW_V,HIGH_V from
(
select split(regexp_replace(LOW_V2,'(\\d*?)(0+)
,'$1|$2'),'\\|') splitted,
LOW_V2,
LOW_V,HIGH_V
from MYTABLE )s;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
操作顺序不是这样的,
首先处理 CTE。处理时 high_v2 不存在
然后处理子查询 (
select split
),然后处理引导查询 (select lpad
)。它是创建 high_v2 的引导查询。编写多个 CTE 以便从上到下处理它们可能会更简单。这样您可以更轻松地查看订单。如果您从较早的 CTE 中继承这些内容,则只能在后面的 CTE 中使用这些内容
。您能看到流程是如何从上到下的,并且每个连续的 CTE 只使用前一个 CTE 中的内容吗?
The order of operations doesn't work like that
The CTE is processed first. At the time it is processed high_v2 doesn't exist
Then the sub query (
select split
) is processed, then the lead query is processed (select lpad
). It is the lead query that creates high_v2It might be simpler for you to write multiple CTE so that they are processed from top down. This way you can more easily see the order. You can only use things in later CTE if you carry them through from an earlier one
Can you see how the flow is top to bottom and each successive CTE only uses things from the previous one..