我正在执行以下查询以获取错误。
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;
你能帮我解决一下这个错误。
先谢谢。
答案 0 :(得分:0)
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
这些连接会影响性能!! 只支持多个连接子查询。
以下查询无任何问题。
select * from(从test中选择id,其中id> 10)a 在a.id = b.id上加入(从测试中选择ID,其中id> 20)b;
在您的情况下,两个过滤器都用于同一个表(cust_focus),否则您可以在不同的表上应用过滤器,如上例所示。