--create table poligonoval as select sum(valore) as valoreTOT, the_geom , nome_pre, cod_pre from (select v.the_geom as the_geom, v.cod_pre, v.nome_pre0, v.nome_pre, area(intersection(v.the_geom, m.the_geom))*m.valori as valore from aziende_pre v, valori m where v.the_geom && m.the_geom and intersects(v.the_geom, m.the_geom)) as val group by the_geom, nome_pre, cod_pre;