mysql - 从mysql查询在hive中实现不等式连接
问题描述
我正在尝试在 hive 中实现一个用 mysql 编写的查询。我知道 hive 不支持 ON 条件下的不等式连接。下面是我的代码,并告诉我实现它的方法。
Select test1.a,
test2.b,
test4.c,
dummy.c
from
test1 join test2 on test1.id = test2.id and test2 != 'ABC'
join test3 on test1.id = test2.id and test3 != 'Archive'
join test4 on test3.id = test4.id and test4 = 'XYZ'
left outer join
(select test1.a,
test2,b
test3.c
from test1 join test2 on test1.id = test2.id and test2 != 'ABC'
join test3 on test1.id = test2.id) dummy
on test3.id = dummy.id
**and (test4.id != 1001 or dummy.c = TRUE)**
left join test5 on test3.id= test5.id
and dummy.c = TRUE
现在用 * 突出显示的条件是我需要知道如何在 hive 中实现它的部分,因为我无法在 ON 条件下实现它,并且如果我将它放在 where 子句结果不匹配。任何在 hive 中重写它的建议将不胜感激。
解决方案
对于从 LEFT JOIN 中选择的列,我在 SELECT 语句中使用了不等式条件作为 case 语句。下面是代码 -
Select test1.a,
test2.b,
test4.c,
case when (test4.id != 1001 or nvl(dummy.c , False))= TRUE then dummy.c end as c0
from
test1 join test2 on test1.id = test2.id and test2 != 'ABC'
join test3 on test1.id = test2.id and test3 != 'Archive'
join test4 on test3.id = test4.id and test4 = 'XYZ'
left outer join
(select test1.a,
test2,b
test3.c
from test1 join test2 on test1.id = test2.id and test2 != 'ABC'
join test3 on test1.id = test2.id) dummy
on test3.id = dummy.id
left join test5 on test3.id= test5.id
and dummy.c = TRUE
推荐阅读
- ios - 将嵌套参数动态添加到 Alamofire 参数
- excel - 如何将公式变成vba语句
- javascript - 如何使用 CefSharp 铬浏览器从 windows.external 执行 C#(WPF) 中的函数?
- python - 创建 django 模型时,它会发布数据,但不会将其保存在数据库中
- android - 登录 AWS 用户池后,会话在三星设备中立即过期
- r - 如何在 case_when 语句中检测多个正则表达式
- typescript - 删除在 ngOnInit() 上订阅服务创建的空行
- sql-server - 如何在 SSRS 报告中验证 FromDate 和 Todate
- ecmascript-6 - 意外的令牌 { 使用 Webpack 4 和 @babel/preset-env
- rest - 针对非 REST 操作的 REST API 设计