[Amazon](500310)无效的操作:目前尚不支持这种类型的IN / NOT IN查询;

时间:2019-02-16 07:13:36

标签: amazon-redshift exists notin

我正在将该查询从Netezza转换为与RedShift dw一起运行。我不断收到此错误。

Amazon无效操作:尚不支持这种类型的IN / NOT IN查询;

我尝试使用'EXISTS / NOT EXISTS'条件进行转换,但仍然没有成功。有人可以给他/她输入我应该如何将其转换为IN,而不是IN部分?

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 个答案:

答案 0 :(得分:0)

您在where子句中具有常量值,不需要existing子句。

您可以在下面尝试-

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)))
);