【问题标题】:PostgreSQL is not recognizing column [duplicate]PostgreSQL 无法识别列 [重复]
【发布时间】:2018-10-08 05:21:12
【问题描述】:

我的查询如下,但由于某种原因 PostgreSQL 无法识别该行。让我知道这里有什么问题。我也在使用 PgAdmin 4。

查询:

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

【问题讨论】:

    标签: sql postgresql alias


    【解决方案1】:

    HAVING 不能使用表达式的别名。你可以HAVING date_part('year', end_of_quarter) = 2013 代替。

    【讨论】:

      猜你喜欢
      • 2018-07-21
      • 2011-04-27
      • 2020-04-06
      • 1970-01-01
      • 1970-01-01
      • 2015-09-26
      • 2016-09-10
      • 1970-01-01
      • 2018-05-21
      相关资源
      最近更新 更多