代码之家  ›  专栏  ›  技术社区  ›  SantiClaus

PostgreSQL无法识别列[重复]

  •  0
  • SantiClaus  · 技术社区  · 8 年前

    查询:

    SELECT date_part('year',end_of_quarter) as yr,industry,sum(gdp) as totalgdp FROM 
    (SELECT * FROM income where industry IN ('Mining','Construction','Utilities')) as MCU
    GROUP BY yr,industry
    HAVING yr = 2013
    ORDER BY totalgdp desc;
    

    结果:

    ERROR:  column "yr" does not exist
    LINE 4: having yr = 2013
                   ^
    SQL state: 42703
    Character: 196
    
    1 回复  |  直到 7 年前
        1
  •  4
  •   Catalyst    8 年前

    HAVING 无法使用表达式的别名。你可以 HAVING date_part('year', end_of_quarter) = 2013