如何在 Hive 中编写非等值连接

发布于 2025-01-09 02:05:44 字数 369 浏览 4 评论 0原文

我的表包括 3 个日期列: dateA 、 dateB 和 dateC 我的要求:

JOIN ON dateA between dateB and dateC

JOIN 在 Teradata 中运行得很好,但在 Hive 中运行时出现错误。

select *
from
table A
left join table B
on A.col1 = B.col1
and A.dateA between B.dateB and B.dateC

错误:

JOIN dateB 中同时遇到左右别名

我真的很感激一些帮助!

My tables include 3 date columns, dateA , dateB and dateC
What I require:

JOIN ON dateA between dateB and dateC

The JOIN works quite well in Teradata, but I'm getting errors while running in Hive.

select *
from
table A
left join table B
on A.col1 = B.col1
and A.dateA between B.dateB and B.dateC

Error:

Both left and right aliases encountered in JOIN dateB

I would really appreciate some help on this!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

星星的軌跡 2025-01-16 02:05:44

原因是 Hive 不支持非等值连接。将 BETWEEN 连接条件移至 WHERE

select *
from
table A
left join table B on A.col1 = B.col1
WHERE (A.dateA between B.dateB and B.dateC)
      OR B.col1 is NULL --allow not joined records from A (left join)

The reason is Hive does not support non-equi joins. Move the BETWEEN join condition to the WHERE

select *
from
table A
left join table B on A.col1 = B.col1
WHERE (A.dateA between B.dateB and B.dateC)
      OR B.col1 is NULL --allow not joined records from A (left join)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文