GIS4DEV / GIS4DEV.github.io

Open Source GIScience & GIS for Development
1 stars 12 forks source link

Spatial joins syntax question #6

Closed pdickson2 closed 4 years ago

pdickson2 commented 4 years ago

Hello. Casey and I are attempting to sum buildings by subward from our building layer. We found a similar script from a post gis forum for calculating racial data. Here is what we've put into the DB Manager:

SELECT builds.subward as sw, sum(builds.flood) as floods, count(*) from builds.osm_id as build FROM builds as builds Join subwards as subward_id ON st_intersects(builds.way, subward_id.geom) GROUP BY subward

We're getting an error with the 'from' line relating to its syntax. We've played around with it but aren't sure what the issues is. Please help.

josephholler commented 4 years ago

I think you're getting the particular error about from because there are two from clauses. Try replacing count(*) from builds.osm_id as build with count(builds.osm_id) as buildcnt

But in the bigger picture, it looks like the goal is to count how many buildings are in each subward. A few observations: