我在Postgres 9.4工作。我有两张桌子:
Table "public.parcel"
Column | Type | Modifiers
ogc_fid | integer | not null default
wkb_geometry | geometry(Polygon,4326) |
county | character varying |
parcel_area | double precision |
Table "public.county"
Column | Type | Modifiers
--------+------------------------+-----------
name | character(1) |
chull | geometry(Polygon,4326) |
area | double precision |
我想在parcel
中找到县的所有唯一值,以及附加宗地的总区域,然后将其作为county
和name
表插入到area
表中分别为{1}}。
我知道如何做到这一步的前半部分:
SELECT county,
SUM(parcel_area) AS area
FROM inspire_parcel
GROUP BY county;
但我不知道如何将这些值插入county
。有人可以建议吗?
我认为它类似于:
UPDATE county SET name, area = (SELECT county, SUM(parcel_area) AS area
FROM inspire_parcel GROUP BY county)
答案 0 :(得分:2)
您使用INSERT INTO
。所以,像这样:
INSERT INTO county
SELECT county, SUM(parcel_area) AS area
FROM inspire_parcel GROUP BY county;