我正在尝试构建一个在FROM语句中使用JOIN语句别名的PostGIS查询,但这是不可能的。还有其他办法吗?
SELECT DISTINCT
ST_Buffer(
ST_Centroid(geom),
ST_Area(geom))
FROM building AS b, ST_Transform(sg.geometry, 31467) AS geom
LEFT JOIN surface_geometry AS sg ON b.id = sg.cityobject_id WHERE ST_Area(geom) < 100
答案 0 :(得分:9)
您可以引入额外级别的子查询。
目前你有:
SELECT DISTINCT ST_Buffer( ST_Centroid(geom), ST_Area(geom) )
FROM building AS b,
ST_Transform(sg.geometry, 31467) AS geom
LEFT JOIN surface_geometry AS sg ON b.id = sg.cityobject_id
WHERE ST_Area(geom) < 100
(我改变了缩进以使它更有意义,虽然我仍然不理解它:你似乎没有使用b中任何地方的值)。你需要这样的东西:
SELECT DISTINCT ST_Buffer( ST_Centroid(geom), ST_Area(geom) )
FROM (
SELECT ST_Transform(sg.geometry, 31467) AS geom
FROM building AS b
LEFT JOIN surface_geometry AS sg ON b.id = sg.cityobject_id
) x
WHERE ST_Area(geom) < 100
答案 1 :(得分:2)
你为什么不试试:
SELECT DISTINCT
ST_Buffer(ST_Centroid(ST_Transform(sg.geometry, 31467),
ST_Area(ST_Transform(sg.geometry, 31467)))
FROM building b LEFT JOIN surface_geometry sg ON (b.id = sg.cityobject_id)
WHERE ST_Area(ST_Transform(sg.geometry, 31467)) < 100;
这也可能有用:
SELECT DISTINCT
ST_Buffer(ST_Centroid(geom), ST_Area(geom))
FROM building b LEFT JOIN surface_geometry sg ON (b.id = sg.cityobject_id) INNER JOIN
ST_Transform(surface_geometry.geometry, 31467) geom ON (ST_Area(geom) < 100);
您可能想要验证()的位置,因为我无法测试它。