【问题标题】:How do I interpret this SQL error with alias name?如何用别名解释这个 SQL 错误?
【发布时间】:2021-01-06 00:14:12
【问题描述】:

我正在尝试使用子查询运行一些代码,但我无法弄清楚为什么会出现错误。

select efile.*
from    
        (select can, 
        sum(case when tax_year = 2018 then IND_RETURNS_IN_SEASON+IND_RETURNS_EXT_SEASON else 0 end) as TY18_efiles,
        sum(case when tax_year = 2019 then IND_RETURNS_IN_SEASON+IND_RETURNS_EXT_SEASON else 0 end) as TY19_efiles
        from pcg_dm.ENT_AGG_CUST_MEASURES
        where can in 
                (select distinct can
                from pcg_dm.ENT_AGG_CUST_MEASURES
                where tax_year in (2019,2019)
                )
        group by 1
        order by 1
        limit 2000
        ) AS efile
join    
        (select can, st.STATE AS TY18_state
        from pcg_dm.ENT_AGG_CUST_ATTRIBUTES AS st
        where tax_year = 2018
        limit 2000
        )AS 18State
        
on
         efile.can=18state.can

我收到以下错误。

[代码:4856,SQL 状态:42601] [Vertica]VJDBC 错误:“18”或附近的语法错误

知道问题是什么吗?

【问题讨论】:

  • “As 18State” - 这是有效的语法吗?表别名中可以有数字吗?试试十八州
  • 感谢您的回复-我试过了,但遇到了同样的问题 [代码:4856,SQL 状态:42601] [Vertica][VJDBC](4856) 错误:在“状态”或附近出现语法错误"
  • 实际上这行得通,谢谢
  • 数字在别名中是可以的,只要它不以它开头。

标签: sql vertica


【解决方案1】:

您在 from 子句之后的第 18 行中为表指定了别名。尝试删除它并重新运行查询。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-15
    • 2010-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-30
    • 1970-01-01
    • 2015-02-25
    相关资源
    最近更新 更多