简体   繁体   English

如何在hive中使用多个子查询

[英]how to use more than 1 sub query in hive

I am executing the below query getting the error. 我正在执行以下查询获取错误。

FAILED: SemanticException [Error 10249]: Line 13:15 Unsupported SubQuery Expression 'master_cd': Only 1 SubQuery expression is supported. FAILED:SemanticException [错误10249]:第13:15行不支持的子查询表达式'master_cd':仅支持1个SubQuery表达式。

SELECT
cfs.roll_no,
max(cclas.crdm_cd) as crdm_cd,
max(cclas.kjtm_cd) as kjtm_cd
FROM cust_focus cfs
LEFT JOIN cust_class cclas
ON (cfs.CF_CLAS_NO = cclas.CLAS_NO
AND cfs.DFS_CD = cclas.DFS_CD 
AND cclas.D_AREA = 'US' 
AND cclas.active_flag = 'Y')
WHERE cfs.roll_no NOT IN (SELECT roll_no FROM class_hist)
AND UPPER(TRIM(cfs.D_AREA)) = 'US'
AND (cfs.master_cd IN (SELECT msk5.msk5_master_cd from msk5_mst_tbl as msk5 WHERE cfs.master_cd=msk5.msk5_master_cd and msk5_m_code=9)
OR cfs.master_cd IS NULL)
group by cfs.roll_no;

Could you please help me how to resolve this error. 你能帮我解决一下这个错误吗?

Thanks in Advance. 提前致谢。

 SELECT 
 cfs.roll_no,   
 max(cclas.crdm_cd) as crdm_cd,
 max(cclas.kjtm_cd) as kjtm_cd
 FROM(select cf.* from cust_focus cf
 join class_hist ch on cf.roll_no!=ch.roll_no
join msk5_mst_tbl msk5 on cf.master_cd = msk5.msk5_master_cd where 
msk5_m_code=9))cfs
LEFT JOIN cust_class cclas
ON (cfs.CF_CLAS_NO = cclas.CLAS_NO
AND cfs.DFS_CD = cclas.DFS_CD 
AND cclas.D_AREA = 'US' 
AND cclas.active_flag = 'Y')
AND UPPER(TRIM(cfs.D_AREA)) = 'US'
OR cfs.master_cd IS NULL

These many joins would impact the performance though!! 这些连接会对性能产生影响!! Only multiple join subqueries are supported. 仅支持多个连接子查询。

below query works without any issue. 以下查询工作没有任何问题。

select * from (select id from test where id>10) a join (select id from test where id>20) b on a.id=b.id; select * from(从test中选择id,其中id> 10)一个连接(从test中选择id,其中id> 20)b a.id = b.id;

In your case ,both filters are being used against same table(cust_focus) only otherwise you could have applied filters on different tables like above example. 在您的情况下,两个过滤器都用于同一个表(cust_focus),否则您可以在不同的表上应用过滤器,如上例所示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM