【问题标题】:postgresql: group by in column update - syntax errorpostgresql:在列更新中分组 - 语法错误
【发布时间】:2020-04-26 01:31:55
【问题描述】:

我正在尝试获取每个区域最高点的高度,我写了这个查询,它工作正常:

select max(obstacle.valhgt_ft) 
from obstacle,
     obstacle_buffer 
where st_contains (obstacle_buffer.geom,obstacle.geom) 
group by obstacle_buffer.primary_id

但是当我尝试使用此查询更新属性时,“组”附近出现语法错误

UPDATE obstacle_buffer 
    SET max_valhgt_ft = max(obstacle.valhgt_ft) 
from obstacle,
     obstacle_buffer 
where st_contains (obstacle_buffer.geom,obstacle.geom) 
group by obstacle_buffer.primary_id

【问题讨论】:

    标签: postgresql group-by sql-update postgis


    【解决方案1】:

    您可以使用共同相关的子查询来执行此操作:

    UPDATE obstacle_buffer 
        SET max_valhgt_ft = (select max(obstacle.valhgt_ft) 
                             from obstacle 
                             where st_contains (obstacle_buffer.geom, obstacle.geom)) 
    

    【讨论】:

      【解决方案2】:

      您尝试更新连接表,但不允许您使用子查询来代替

      你可以这样做

      UPDATE obstacle_buffer 
      SET max_valhgt_ft = (select max(obstacle.valhgt_ft) 
                           from obstacle,obstacle_buffer 
                           where st_contains (obstacle_buffer.geom,obstacle.geom) 
                           group by obstacle_buffer.primary_id)
      
      

      【讨论】:

      • max_valhgt_ft 来自哪张桌子?
      • 子查询中不需要重复obstacle_buffer
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多