配置单元获取非现有和现有数据的列表 [英] hive get list of non existing and existing data

查看:131
本文介绍了配置单元获取非现有和现有数据的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两张表:

 注册全球
ID | uom ID | uom
------------------ ----------------
1 | kg 1 | kg
1 | gm 1 | gm
1 | ml 3 | pl
3 | pl

所需输出:

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

查询已尝试:

  SELECT reg.id,reg.UOM,glob.uom 
FROM reg
LEFT JOIN全局全局变量
ON reg.id = reg.id和reg.uom = glob.uom
WHERE glob.uom为空且reg.id = 1

输出:

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

预先致谢。

解决方案

删除where子句。只需左外连接就可以得到结果

 选择Reg.ID,Reg.uom作为reg,Global.uom作为glob 
从Reg
离开外部联接Global.Reg.ID = Global .ID和Reg.uom = Global.uom


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.

解决方案

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

这篇关于配置单元获取非现有和现有数据的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆