Hive 连接 CTE

发布于 2025-01-12 16:40:57 字数 560 浏览 0 评论 0原文

有人可以帮我在下面的查询中添加注释的连接条件吗?如果我执行这个查询工作正常,但是当我尝试添加一个在下面的查询中注释的连接条件时,它无法访问列 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何其悲哀 2025-01-19 16:40:57

操作顺序不是这样的,

首先处理 CTE。处理时 high_v2 不存在

然后处理子查询 (select split),然后处理引导查询 (select lpad)。它是创建 high_v2 的引导查询。

编写多个 CTE 以便从上到下处理它们可能会更简单。这样您可以更轻松地查看订单。如果您从较早的 CTE 中继承这些内容,则只能在后面的 CTE 中使用这些内容

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 
), 

s AS (
 select    
  split(regexp_replace(LOW_V2,'(\\d*?)(0+)

。您能看到流程是如何从上到下的,并且每个连续的 CTE 只使用前一个 CTE 中的内容吗?

,'$1|$2'),'\\|') splitted, LOW_V2, LOW_V,HIGH_V from MYTABLE ), t AS ( select lpad(concat(splitted[0],translate(splitted[1],'0','9')),18,0) as high_V2, LOW_V2, LOW_V, HIGH_V from s ) SELECT * from t WHERE high_v = high_v2

。您能看到流程是如何从上到下的,并且每个连续的 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_v2

It 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

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 
), 

s AS (
 select    
  split(regexp_replace(LOW_V2,'(\\d*?)(0+)

Can you see how the flow is top to bottom and each successive CTE only uses things from the previous one..

,'$1|$2'),'\\|') splitted, LOW_V2, LOW_V,HIGH_V from MYTABLE ), t AS ( select lpad(concat(splitted[0],translate(splitted[1],'0','9')),18,0) as high_V2, LOW_V2, LOW_V, HIGH_V from s ) SELECT * from t WHERE high_v = high_v2

Can you see how the flow is top to bottom and each successive CTE only uses things from the previous one..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文