我正在尝试在SELECT语句中定义多个列,
问题是column "col_name" does not exist
当我尝试为as
计算定义第二个列名时,我不断收到错误消息。这是我的查询:
SELECT fa.farmer_id as farmer,
ST_area(fi.geom)/10000 * cr.yieldperhectar as totalyield,
totalyield * 1000 * cr.priceperkg as revenue,
revenue - cr.waterdemandpermonth*1980 as income,
extract(year from wu.usedate) as yyyy
FROM farmers as fa JOIN
fields as fi ON fa.farmer_id = fi.farmer JOIN
fieldcrops as fc ON fi.id = fc.field_id JOIN
crops as cr ON fc.crop_id = cr.crop_id JOIN
wateruse as wu ON fi.id = wu.field_id,
valves as va
我得到的警告是
你可以忽略第 6 行部分,我的查询中有注释掉的行。
我在这里做错了吗?
编辑
在这里找到了答案:PostgreSQL 视图:在另一个计算字段中引用一个计算字段,这要归功于所有重复的标志(之前找不到)。
必须重新计算该字段。