无法在查询中找到错误 - Snowflake

Unable to find error in the query - Snowflake

错误:SQL 编译错误:错误行 105 在位置 8 无效标识符 'INTENT'. 有两个 CTE,然后是 select 语句。如果 运行 分开,第一个 CTE 工作正常,错误在第二个 CTE 中。我不确定是什么导致了语法错误。

提前致谢。

WITH Test AS(
SELECT a.NUMBER
      ,b.Event_date 
      ,b.SESSION_ID  
      ,b.EVENT_TIMESTAMP 
      ,b.CURRENT_VIEW_NAME 
FROM PD_PRESENT.CUS.CUS_ISSUE as a
LEFT JOIN PD_PRESEN.CUS.REQ as b
ON a.NUMBER = B.NUMBER 
WHERE a.CREATED_DATE BETWEEN '2022-02-24 00:00:00.000' AND '2022-02-27 23:59:59.997'
AND b.Event_date BETWEEN '2022-02-24 00:00:00.000' AND '2022-02-27 23:59:59.997'
AND b.USER_GROUP = 'Customer'  
),

Consolidate AS(
SELECT DISTINCT 
             a.Number
            ,a.EVENT_DATE
            ,a.EVENT_TIMESTAMP
            ,a.Current_View_Name
            ,CASE 
            -- MOAT
                WHEN a.Current_View_Name LIKE '%CONDO%' THEN 'MOAT'
                WHEN a.Current_View_Name LIKE '%RENTER%' THEN 'MOAT'
                WHEN a.Current_View_Name LIKE '%FIRE%' THEN 'MOAT'
            -- BOAT
                WHEN a.Current_View_Name LIKE '%WATER%' THEN 'BOAT'
                WHEN a.Current_View_Name LIKE '%BOAT%' THEN 'BOAT'
            -- Error
                WHEN a.Current_View_Name LIKE '%Error%' THEN 'ERROR'
                        END AS "Intent"

            ,CASE
                WHEN a.Current_View_Name LIKE '%Mobile%' THEN 'MOBILE' ELSE 'DESKTOP'
            END AS "Source"
FROM Test as a
)
  
SELECT 
        a.NUMBER 
       ,a.Event_Date as "ProcessedDate"
       ,Intent as "TransactionIntent" -- **LINE 105**
       ,MIN(a.EVENT_TIMESTAMP) as "TransactionStart"
       ,MAX(a.EVENT_TIMESTAMP) as "TransactionEnd"
       ,'SelfService' AS "SourceType"
FROM Consolidate as a
WHERE a.Intent IS NOT NULL
GROUP BY a.NUMBER
        ,a.ProcessedDate
        ,a.Intent
   

Snowflake 将未加引号的标识符视为大写。而引用的标识符是 case-sensitive。因此,您可能需要将列别名指定为 "INTENT"(全部大写),以便稍后在不使用引号的情况下引用它。

如果需要,可以使用 QUOTED_IDENTIFIERS_IGNORE_CASE 更改此行为。

QUOTED_IDENTIFIERS_IGNORE_CASE:

Specifies whether letters in double-quoted object identifiers are stored and resolved as uppercase letters. By default, Snowflake preserves the case of alphabetic characters when storing and resolving double-quoted identifiers. (See Identifier Resolution.) You can use this parameter in situations in which third-party applications always use double quotes around identifiers.