预期<EOF> SQL

时间:2019-06-19 21:44:54

标签: sql

我正在Spark上运行一个进程,该进程大部分使用SQL。在其中一个工作流程中,出现以下错误:

“预期的输入来自'的不匹配”

代码是

 select a.ACCOUNT_IDENTIFIER,a.LAN_CD, a.BEST_CARD_NUMBER,  
 decision_id, 
 case when a.BEST_CARD_NUMBER = 1 then 'Y' else 'N' end as best_card_excl_flag 
 from (select a.ACCOUNT_IDENTIFIER,a.LAN_CD, a. decision_id row_number()
 over (partition by CUST_GRP_MBRP_ID 
    order by coalesce(BEST_CARD_RANK,999)) as BEST_CARD_NUMBER 
 from Accounts_Inclusions_Exclusions_Flagged a) a 

我无法弄清楚我一生中的错误是什么

我尝试检查逗号错误或意外的括号,但这似乎不是问题所在。

3 个答案:

答案 0 :(得分:0)

我认为您的问题出在内部查询中。您在a.decision_id之间留有空格,并且在decision_idrow_number()之间缺少逗号。

这是您想要的吗?

 SELECT
    a.ACCOUNT_IDENTIFIER,
    a.LAN_CD,
    a.BEST_CARD_NUMBER,
    decision_id, 
    CASE WHEN a.BEST_CARD_NUMBER = 1 THEN 'Y' ELSE 'N' END AS best_card_excl_flag 
 FROM (
    SELECT
        a.ACCOUNT_IDENTIFIER,
        a.LAN_CD,
        a.decision_id,
        row_number() OVER (partition BY CUST_GRP_MBRP_ID ORDER BY COALESCE(BEST_CARD_RANK,999)) AS BEST_CARD_NUMBER 
    FROM Accounts_Inclusions_Exclusions_Flagged A
 ) A; 

答案 1 :(得分:0)

我想说的只是语法错误。我认为它发生在最后一个FROM语句的原始查询的末尾。当然,我可能是错的。

尝试以下操作:

'SELECT a.ACCOUNT_IDENTIFIER, a.LAN_CD, a.BEST_CARD_NUMBER, decision_id,
    CASE    
        WHEN a.BEST_CARD_NUMBER = 1 THEN 'Y'
        ELSE 'N'
    END AS best_card_excl_flag
FROM (SELECT ROW_NUMBER() OVER(PARTITION BY CUST_GRP_MBRP
                                ORDER BY COALESCE(BEST_CARD_RANK, 999)) AS 
BEST_CARD_NUMBER,
            a.ACCOUNT_IDENTIFIER, a.LAN_CD, a.decision_id
    FROM Accounts_Inclusions_Exclusions_Flagged) AS a;'

我希望这会有所帮助。

答案 2 :(得分:0)

在代码的第四行,您只需在a.decision_id之后添加一个逗号,因为over_row(number)是单独的列/函数。

P.S .:尝试在嵌套的select语句中使用缩进,这样您和您的同龄人就可以轻松理解代码。干杯!