Hive Left join on 与Where 优先级问题讨论2

SQL1

SELECT
					a.AptOrgNum,
					a.iocValue,
					a.iocType,
					b.ReportName,
					b.ReportPublishTime,
					b.ReportPubOrg
				FROM
					extract_ioc_infor_table a
				LEFT JOIN extract_report_table b ON (a.sourceUrl = b.pdf_file and a.sourceUrl !='' and b.pdf_file !='' )

SQL2

SELECT
	a.AptOrgNum,
	a.iocValue,
	a.iocType,
	b.ReportName,
	b.ReportPublishTime,
	b.ReportPubOrg
FROM
	extract_ioc_infor_table a
LEFT JOIN extract_report_table b ON a.sourceUrl = b.pdf_file
WHERE
	a.sourceUrl != ''
AND b.pdf_file != ''

SQL3 不做过滤空值

SELECT
	a.AptOrgNum,
	a.iocValue,
	a.iocType,
	b.ReportName,
	b.ReportPublishTime,
	b.ReportPubOrg
FROM
	extract_ioc_infor_table a
LEFT JOIN extract_report_table b ON a.sourceUrl = b.pdf_file

执行结果
SQL1:1543888条

SQL2:85756条
SQL3:1543888条

结论
1.对于a表 left join b表 ,过滤条件在on中:忽略a表的过滤条件,b表的过滤条件只会导致不满足条件的记录在b表的所有字段上都为空;过滤条件在where中:过滤掉所有不满足条件的记录。
2.left join时on中条件无过滤记录作用,后做where条件过滤记录。on 优先级高于 where

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大数据学习僧

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值