开发者社区> 问答> 正文

maxcompute left outer join 不等值On 连接条件查询

原来在oracle 里面的SQL语句,
insert into tmp_t_mz_ry_jhdj_add

  select a.*
    from tmp_t_mz_ry_jhdj a
    left join t_jztp_gx_sum b on ((a.zgxr = b.zgxr and a.cgxr = b.cgxr) or
                                 (a.zgxr = b.cgxr and a.cgxr = b.zgxr))
                             and b.gxxl like '1104%'
    left join tmp_t_mz_ry_lhdj c on a.zgxr = c.zgxr
                                and a.cgxr = c.cgxr
                                and a.gxfssj < c.gxfssj
   where b.zgxr is null
     and c.zgxr is null;

在left join on条件中存在不等值查询,maxcompute left outer join不支持,但是表的数据量都非常大,用map join不合适,怎样修改SQL ,实现原来的效果

展开
收起
猫1984 2017-07-04 11:25:20 3931 0
1 条回答
写回答
取消 提交回答
  • 把不等值放在关联之后的where中过滤,把b、c表中的过滤条件提到子查询中提前过滤数据量,减少join的数据量,望采纳,谢谢!

    select a.*
    from 
    (select * from tmp_t_mz_ry_jhdj)a
    left join 
    (select * from t_jztp_gx_sum where gxxl like '1104%' and zgxr is null)b 
    on ((a.zgxr = b.zgxr and a.cgxr = b.cgxr) or
        (a.zgxr = b.cgxr and a.cgxr = b.zgxr))
    left join 
    (select * from tmp_t_mz_ry_lhdj where zgxr is null)c 
    on a.zgxr = c.zgxr
       and a.cgxr = c.cgxr
     where a.gxfssj < c.gxfssj;
    2019-07-17 21:21:43
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Data+AI时代大数据平台应该如何建设 立即下载
大数据AI一体化的解读 立即下载
极氪大数据 Serverless 应用实践 立即下载