Hive 嵌套查询左连接
Hive nested query left join
我是 Hive 的新手,我想实现以下查询
select a.controlid,
b.name as campaign,
a.controlactivityid as activitysource,
c.code as codemyaprc,
c.label_en as label_en,
c.label_fr as label_fr
from bo_h_control.bridgeactivity a
join suvh_econtrol.TMP_GPS_REF b ON a.controlcampaignid =
b.ps_cam_id
left join srv_h_a8460_fpc.activity c
ON a.controlactivityid=c.code
and c.date_creation= select
max(date_creation) from srv_h_a8460_fpc.activity
在最后一个左连接之前它工作正常。嵌套查询显然未在 hive 中授权。
我该如何解决这个问题。
使用子查询代替连接table:
select a.controlid,
b.name as campaign,
a.controlactivityid as activitysource,
c.code as codemyaprc,
c.label_en as label_en,
c.label_fr as label_fr
from bo_h_control.bridgeactivity a
join suvh_econtrol.TMP_GPS_REF b ON a.controlcampaignid =
b.ps_cam_id
left join (select c.*, max(date_creation) over() as max_date_creation
from srv_h_a8460_fpc.activity c
) c ON a.controlactivityid=c.code
and c.date_creation=c.max_date_creation
或者最好将最后一个连接条件移动到子查询的 WHERE 子句中:
select a.controlid,
b.name as campaign,
a.controlactivityid as activitysource,
c.code as codemyaprc,
c.label_en as label_en,
c.label_fr as label_fr
from bo_h_control.bridgeactivity a
join suvh_econtrol.TMP_GPS_REF b ON a.controlcampaignid =
b.ps_cam_id
left join (select * from
(
select c.*, max(date_creation) over() as max_date_creation
from srv_h_a8460_fpc.activity c
)c where max_date_creation=date_creation
) c ON a.controlactivityid=c.code
我是 Hive 的新手,我想实现以下查询
select a.controlid,
b.name as campaign,
a.controlactivityid as activitysource,
c.code as codemyaprc,
c.label_en as label_en,
c.label_fr as label_fr
from bo_h_control.bridgeactivity a
join suvh_econtrol.TMP_GPS_REF b ON a.controlcampaignid =
b.ps_cam_id
left join srv_h_a8460_fpc.activity c
ON a.controlactivityid=c.code
and c.date_creation= select
max(date_creation) from srv_h_a8460_fpc.activity
在最后一个左连接之前它工作正常。嵌套查询显然未在 hive 中授权。
我该如何解决这个问题。
使用子查询代替连接table:
select a.controlid,
b.name as campaign,
a.controlactivityid as activitysource,
c.code as codemyaprc,
c.label_en as label_en,
c.label_fr as label_fr
from bo_h_control.bridgeactivity a
join suvh_econtrol.TMP_GPS_REF b ON a.controlcampaignid =
b.ps_cam_id
left join (select c.*, max(date_creation) over() as max_date_creation
from srv_h_a8460_fpc.activity c
) c ON a.controlactivityid=c.code
and c.date_creation=c.max_date_creation
或者最好将最后一个连接条件移动到子查询的 WHERE 子句中:
select a.controlid,
b.name as campaign,
a.controlactivityid as activitysource,
c.code as codemyaprc,
c.label_en as label_en,
c.label_fr as label_fr
from bo_h_control.bridgeactivity a
join suvh_econtrol.TMP_GPS_REF b ON a.controlcampaignid =
b.ps_cam_id
left join (select * from
(
select c.*, max(date_creation) over() as max_date_creation
from srv_h_a8460_fpc.activity c
)c where max_date_creation=date_creation
) c ON a.controlactivityid=c.code