简体   繁体   中英

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.

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;

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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