hive get list of non existing and existing data

痴心易碎 提交于 2019-12-12 05:57:22

问题


Two tables :

Reg                      Global
ID | uom                 ID  | uom    
------------------           ----------------
1  | kg                   1  | kg
1  | gm                   1  | gm
1  | ml                   3  | pl
3  | pl     

Desired output:

ID | reg    | glob   
------------------  
1  | kg      | kg
1  | gm      | gm
1  | ml      | null
3  | pl      | pl 

Query tried:

SELECT reg.id,  reg.UOM  ,glob.uom
FROM reg
LEFT JOIN global glob
ON reg.id=reg.id  and reg.uom = glob.uom
WHERE  glob.uom is null and reg.id =1

Output:

reg.id | reg.uom | glob.uom 
1      | ml      | null

Thanks in advance.


回答1:


Remove the where clause.Just the left outer join will get you the results

select Reg.ID, Reg.uom as reg, Global.uom as glob
from Reg
left outer join Global on Reg.ID = Global.ID and Reg.uom = Global.uom


来源:https://stackoverflow.com/questions/46900122/hive-get-list-of-non-existing-and-existing-data

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!