I have 2 tables : wgo (lines) and wbn (polygons) With this code, I can display the length of each road inside a polygon. If I have a polygon with 2 roads in it, as a result I get 2 rows with the 2 lengths displayed.

But what I really want, is the total length of roads in the polygon, so I want to SUM them up.. How can this be done ?

SELECT wbn_uidn, wgo_uidn, ST_Length(ST_Intersection(wgo_geom,wbn_geom))
FROM wbn, wgo
WHERE ST_Intersects(wgo_geom,wbn_geom)='t' 
SELECT wbn_uidn, sum(ST_Length(ST_Intersection(wgo_geom,wbn_geom)))
FROM wbn, wgo
WHERE ST_Intersects(wgo_geom,wbn_geom) 
GROUP BY wbn_uidn;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.