我的查询在下面,但是由于某种原因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
答案 0 :(得分:4)
HAVING
不能使用表达式的别名。您可以改为HAVING date_part('year', end_of_quarter) = 2013
。