sql—如何重构左外部联接中的and和or,因为配置单元不支持or in子句

zsohkypk  于 2021-06-24  发布在  Hive
关注(0)|答案(1)|浏览(379)

我正在运行一个hive-left-outer-join查询,它涉及on子句中的and和or。配置单元不支持on子句中的或。我该如何重写它以在Hive中运行?如果union是答案之一,请注意我使用的hive版本不支持union。仅支持union all。

select 

* 

from
a
left outer join b on a.a1=b.b1
left outer join c on c.c10=a.15 and (c.12=a.25 or c.13=a.25)
left outer join d on d.d1=a.a5
where
?
wyyhbhjk

wyyhbhjk1#

你可以合并 UNION ALLDISTINCT :

SELECT DISTINCT *
FROM (
  select *
  from a
  left outer join b on a.a1=b.b1
  left outer join c on c.c10=a.15 and c.12=a.25 
  left outer join d on d.d1=a.a5
  where ?
  UNION ALL
  select *
  from a
  left outer join b on a.a1=b.b1
  left outer join c on c.c10=a.15 and c.13=a.25
  left outer join d on d.d1=a.a5
  where ?
) s

相关问题