Calculating total area of polygons that intersects with other polygons in Postgis
<p>I want to calculate in Postgis the total area of 'a' polygons, that intersects with others 'b'.</p>

<pre><code>   SELECT DISTINCT a.fk_sites, 
   SUM(ST_Area(a.the_geom)/100) as area
   FROM parcelles a, sites b
   WHERE st_intersects(a.the_geom,b.the_geom)
   GROUP BY a.fk_sites
</code></pre>

<p>I need to do a SELECT DISTINCT because 'a' polygons may intersect with several 'b' polygons, so that the returned 'a' polygons appear a few times.</p>

<p>This works fine, I just have the problem, that not all areas are calculated correctly. A few seam to ignore the DISTINCT case, so that the calculated area reflects the SUM of all, even the duplicated 'a' records (even if they should be eliminated).
When I do a query without the SUM function, I get the correct number of 'a' polygons and while adding their area I get the right value.  </p>

<pre><code>  SELECT DISTINCT a.fk_sites, 
   ST_Area(a.the_geom)/100 as area
   FROM parcelles a, sites b
   WHERE st_intersects(a.the_geom,b.the_geom)
   ORDER BY a.fk_sites
</code></pre>

<p>Is the combination of SELECT DISTINCT and the SUM / GROUP BY not correct?</p>