hive left join on关联后用in条件过滤问题

当left 或 inner join 关联条件 需要查另外一个表中字段,则可以使用下面的方法。

下面语法是错误写法,运行不会通过。

sql 复制代码
select t1.* from t1 
left join t2 on t1.acct_no = t2.acct_no
and t1.code in (select type1 from tt)

下面是正确的实现思路,提前在主表中,做好打标字段处理。

sql 复制代码
select t1.* 
from (
select 
*,
case when tt.type1 is not null then 1 else 0 end as flag
from t1
left join tt
on code = type1
 )t1
left join t2 on t1.acct_no = t2.acct_no
and flag = 1
相关推荐
对许3 小时前
Hadoop的运行模式
大数据·hadoop·分布式
向日葵花子(* ̄︶ ̄)6 小时前
hive sql limit offset不起作用
hadoop
2302_799525747 小时前
【Hadoop】如何理解MapReduce?
数据库·hadoop·mapreduce
火龙谷8 小时前
hadoop第3课(hdfs shell常用命令)
hadoop·hdfs·npm
神秘打工猴9 小时前
数据仓库为什么要分层
大数据·数据仓库·spark
好记性+烂笔头18 小时前
Hive八股
hive
StableAndCalm19 小时前
什么是hive
数据仓库·hive·hadoop
好记性+烂笔头1 天前
Hadoop八股
大数据·hadoop·分布式
Python数据分析与机器学习1 天前
《基于Hadoop的出租车需求预测系统设计与实现》开题报告
大数据·hadoop·分布式·python·算法·数据挖掘·数据分析
StableAndCalm1 天前
什么是hadoop
大数据·hadoop·分布式