0

/表 TEMP 有客户哈希、生效开始日期和生效结束日期。表 CDTLS 有客户哈希,生效开始日期。我想客户哈希,生效,来自 TEMP 和 CDTLS 的客户名称。我正在计算 CDTLS 结束日期并将其与 TEMP.EFFECTIVE_FROM 和 TEMP_EFFECTIVE_TO 日期进行比较。我收到无法评估不受支持的子查询的错误。/

SELECT
        TEMP.CUSTOMER_HASH, 
        TEMP.EFFECTIVE_FROM,
        TEMP.EFFECTIVE_TO,
        CDTLS.NAME
    FROM TEMP
    LEFT CDTLS 
    ON 
    TEMP.CUSTOMER_HASH = CDTLS.CUSTOMER_HASH
    AND 
    CDTLS.EFFECTIVE_FROM <= TEMP.EFFECTIVE_FROM
    AND 
     (
     SELECT VW.EFFECTIVE_TO FROM  
     
        (
         SELECT CUSTOMER_HASH, EFFECTIVE_FROM, LEAD(EFFECTIVE_FROM, 1, '9999-12-31') OVER (PARTITION 
              BY CUSTOMER_HASH ORDER BY EFFECTIVE_FROM ASC) AS EFFECTIVE_TO
         FROM CUST_DETAILS
        ) AS VW
     WHERE CDTLS.CUSTOMER_HASH = VW.CUSTOMER_HASH AND CDTLS.EFFECTIVE_FROM = VW.EFFECTIVE_FROM
     ) >= TEMP.EFFECTIVE_TO
    ;
4

2 回答 2

0

我想你想运行这个查询:

SELECT
        TEMP.CUSTOMER_HASH, 
        TEMP.EFFECTIVE_FROM,
        TEMP.EFFECTIVE_TO,
        CDTLS.NAME
    FROM TEMP
    LEFT join  CDTLS 
    ON 
    TEMP.CUSTOMER_HASH = CDTLS.CUSTOMER_HASH
    AND 
    CDTLS.EFFECTIVE_FROM <= TEMP.EFFECTIVE_FROM
    left join         (
         SELECT CUSTOMER_HASH, EFFECTIVE_FROM, LEAD(EFFECTIVE_FROM, 1, '9999-12-31') OVER (PARTITION 
              BY CUSTOMER_HASH ORDER BY EFFECTIVE_FROM ASC) AS EFFECTIVE_TO
         FROM CUST_DETAILS
        ) AS VW on CDTLS.CUSTOMER_HASH = VW.CUSTOMER_HASH AND CDTLS.EFFECTIVE_FROM = VW.EFFECTIVE_FROM
    where  
   VW.EFFECTIVE_TO >= TEMP.EFFECTIVE_TO

于 2021-08-23T11:04:20.997 回答
0

您可以尝试在选择查询中使用 MIN / MAX / LISTAGG 等,以使其确定性标量以检查是否有帮助。

https://docs.snowflake.net/manuals/user-guide/querying-subqueries.html#differences-between-correlated-and-non-correlated-subqueries

于 2021-08-24T01:44:08.353 回答