[Amazon](500310) Invalid operation: This type of IN/NOT IN query is not supported yet;

自作多情 提交于 2019-12-20 05:47:21

问题


I'm converting this query from Netezza to run with my RedShift dw. I'm continuously getting this error.

Amazon Invalid operation: This type of IN/NOT IN query is not supported yet;

I have tried converting it using 'EXISTS/NOT EXISTS' condition but still not successful. Can someone give his/her input how should i convert that IN, NOT IN part?

CREATE TEMP TABLE TMP_EMPLY_BRND AS 
(
Select EMPLY_SRRGT_ID,
           EMPLY_PRMRY_BRND_PRDCT_DPRTMNT_EFF_STRT_DT_KEY,
           EMPLY_PRMRY_PRDCT_DPRTMNT_GRP_SRRGT_ID,

From           
((
 (SELECT E.EMPLY_SRRGT_ID,
           E.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT_EFF_STRT_DT_KEY,
    FROM INS_EDW_CP.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT E
    where (((E.EMPLY_SRRGT_ID, E.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT_EFF_STRT_DT_KEY, E.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT_EFF_END_DT_KEY )=ANY
          (SELECT distinct A.EMPLY_SRRGT_ID , A.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT_EFF_STRT_DT_KEY, A.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT_EFF_END_DT_KEY
           FROM INS_EDW_CP.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT A
           WHERE (A.EMPLY_PRMRY_BRND_SRRGT_ID > 0 )
           GROUP BY A.EMPLY_SRRGT_ID , A.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT_EFF_STRT_DT_KEY, A.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT_EFF_END_DT_KEY
           HAVING ((COUNT(DISTINCT A.EMPLY_PRMRY_PRDCT_DPRTMNT_GRP_SRRGT_ID) > 1)
                   AND (COUNT(DISTINCT A.EMPLY_PRMRY_BRND_SRRGT_ID) = 1))))
                  or ((E.EMPLY_MRCHNDS_GRP_NBR , E.EMPLY_PRMRY_BRND_SRRGT_ID)  in  (select 947,-1)
                   or  (E.EMPLY_MRCHNDS_GRP_NBR , E.EMPLY_PRMRY_BRND_SRRGT_ID) in  (select 952,-1) ))
    Group BY
    E.EMPLY_SRRGT_ID, 
UNION
SELECT E.EMPLY_SRRGT_ID,
           E.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT_EFF_STRT_DT_KEY,
    FROM INS_EDW_CP.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT E
    where    (
    ((E.EMPLY_SRRGT_ID, E.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT_EFF_STRT_DT_KEY, E.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT_EFF_END_DT_KEY )<>ALL
          (SELECT distinct A.EMPLY_SRRGT_ID , A.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT_EFF_STRT_DT_KEY, A.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT_EFF_END_DT_KEY
           FROM INS_EDW_CP.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT A
           WHERE (A.EMPLY_PRMRY_BRND_SRRGT_ID > 0 )
           GROUP BY A.EMPLY_SRRGT_ID , A.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT_EFF_STRT_DT_KEY, A.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT_EFF_END_DT_KEY
           HAVING ((COUNT(DISTINCT A.EMPLY_PRMRY_PRDCT_DPRTMNT_GRP_SRRGT_ID) > 1)
                   AND (COUNT(DISTINCT A.EMPLY_PRMRY_BRND_SRRGT_ID) = 1)))
                   )
                   and ((E.EMPLY_MRCHNDS_GRP_NBR,E.EMPLY_PRMRY_BRND_SRRGT_ID) not in  (select 947,-1)
                   and (E.EMPLY_MRCHNDS_GRP_NBR,E.EMPLY_PRMRY_BRND_SRRGT_ID) not in  (select 952,-1)))
) X
JOIN INS_EDW_CP.DT D1 
ON D1.DT_KEY between X.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT_EFF_STRT_DT_KEY and X.EFF_END_DT_KEY
JOIN INS_EDW_CP.DT_CLNDR_TYPE D2
on ((D1.DT_KEY = D2.DT_KEY) AND (D2.CLNDR_TYPE = 1)))
);

回答1:


You have constant values in where clause, you don't need exists clause.

Can you try below -

CREATE TEMP TABLE TMP_EMPLY_BRND AS 
(
Select EMPLY_SRRGT_ID,
           EMPLY_PRMRY_BRND_PRDCT_DPRTMNT_EFF_STRT_DT_KEY,
           EMPLY_PRMRY_PRDCT_DPRTMNT_GRP_SRRGT_ID,

From           
((
 (SELECT E.EMPLY_SRRGT_ID,
           E.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT_EFF_STRT_DT_KEY,
    FROM INS_EDW_CP.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT E
    where (((E.EMPLY_SRRGT_ID, E.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT_EFF_STRT_DT_KEY, E.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT_EFF_END_DT_KEY )=ANY
          (SELECT distinct A.EMPLY_SRRGT_ID , A.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT_EFF_STRT_DT_KEY, A.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT_EFF_END_DT_KEY
           FROM INS_EDW_CP.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT A
           WHERE (A.EMPLY_PRMRY_BRND_SRRGT_ID > 0 )
           GROUP BY A.EMPLY_SRRGT_ID , A.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT_EFF_STRT_DT_KEY, A.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT_EFF_END_DT_KEY
           HAVING ((COUNT(DISTINCT A.EMPLY_PRMRY_PRDCT_DPRTMNT_GRP_SRRGT_ID) > 1)
                   AND (COUNT(DISTINCT A.EMPLY_PRMRY_BRND_SRRGT_ID) = 1))))
                  or ((E.EMPLY_MRCHNDS_GRP_NBR , E.EMPLY_PRMRY_BRND_SRRGT_ID)  in  ( 947,-1)
                   or  (E.EMPLY_MRCHNDS_GRP_NBR , E.EMPLY_PRMRY_BRND_SRRGT_ID) in  ( 952,-1) ))
    Group BY
    E.EMPLY_SRRGT_ID, 
UNION
SELECT E.EMPLY_SRRGT_ID,
           E.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT_EFF_STRT_DT_KEY,
    FROM INS_EDW_CP.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT E
    where    (
    ((E.EMPLY_SRRGT_ID, E.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT_EFF_STRT_DT_KEY, E.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT_EFF_END_DT_KEY )<>ALL
          (SELECT distinct A.EMPLY_SRRGT_ID , A.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT_EFF_STRT_DT_KEY, A.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT_EFF_END_DT_KEY
           FROM INS_EDW_CP.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT A
           WHERE (A.EMPLY_PRMRY_BRND_SRRGT_ID > 0 )
           GROUP BY A.EMPLY_SRRGT_ID , A.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT_EFF_STRT_DT_KEY, A.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT_EFF_END_DT_KEY
           HAVING ((COUNT(DISTINCT A.EMPLY_PRMRY_PRDCT_DPRTMNT_GRP_SRRGT_ID) > 1)
                   AND (COUNT(DISTINCT A.EMPLY_PRMRY_BRND_SRRGT_ID) = 1)))
                   )
                   and ((E.EMPLY_MRCHNDS_GRP_NBR,E.EMPLY_PRMRY_BRND_SRRGT_ID) not in  ( 947,-1)
                   and (E.EMPLY_MRCHNDS_GRP_NBR,E.EMPLY_PRMRY_BRND_SRRGT_ID) not in  ( 952,-1)))
) X
JOIN INS_EDW_CP.DT D1 
ON D1.DT_KEY between X.EMPLY_PRMRY_BRND_PRDCT_DPRTMNT_EFF_STRT_DT_KEY and X.EFF_END_DT_KEY
JOIN INS_EDW_CP.DT_CLNDR_TYPE D2
on ((D1.DT_KEY = D2.DT_KEY) AND (D2.CLNDR_TYPE = 1)))
);


来源:https://stackoverflow.com/questions/54720771/amazon500310-invalid-operation-this-type-of-in-not-in-query-is-not-supporte

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