 		-- The areas crossing, with more than one-third of the intesecting area
 		-- WITHIN
 		SELECT
-			q.the_geom AS the_geom,
+			v.the_geom AS the_geom,
 			ofa_year,
 			ofa_month,
 			q.sa_code,

		FROM
			(
				SELECT
					ST_Multi(ST_Buffer(ST_Intersection(f.the_geom, g.the_geom),0.0)) AS the_geom,
					sa_code
				FROM
					zaf.demog_sas AS f,
					zaf.prob_hazard AS g
				WHERE
						ST_Intersects(f.the_geom, g.the_geom)
					AND
						NOT ST_Within(f.the_geom, g.the_geom)
			) AS j,
			(
				SELECT
					the_geom,
					m.sa_code,
					m.mn_name,
					m.dc_code,
					m.dc_name,
					m.pr_name,
					total AS pop_size,
					total * pop_c / pop_y AS pop_curr,
					lz_code,
					'normal' AS lz_affected
				FROM
					(
						SELECT CAST(dc_mdb_code AS varchar(6)) AS dc_mdb_code, sum(pop) AS pop_c
						FROM zaf.tbl_pop_proj
						WHERE year_mid = EXTRACT(year FROM current_date)
						GROUP BY dc_mdb_code
						) AS k,
					zaf.demog_sas AS m,
					zaf.tbl_pop_agegender_12y AS n,
					(
						SELECT dc_code, sum(total) AS pop_y
						FROM zaf.tbl_pop_agegender_12y, zaf.demog_sas
						WHERE zaf.demog_sas.sa_code = zaf.tbl_pop_agegender_12y.sa_code
						GROUP BY dc_code
						) AS p
				WHERE
						m.sa_code = n.sa_code
					AND
						k.dc_mdb_code = m.dc_mdb_code
					AND
						m.dc_code = p.dc_code
				) AS q
/*			(
				SELECT
					gid,
					the_geom,
					k.sa_code,
					mn_code,
					dc_code,
					pr_code,
					total AS pop_size,
					lz_code
				FROM
					zaf.demog_sas AS k,
					zaf.tbl_pop_agegender_12y AS l
				WHERE
					k.sa_code = l.sa_code
			) AS m */
		WHERE
				q.sa_code = j.sa_code
			AND
				ST_Area(q.the_geom) >= 3 * ST_Area(j.the_geom)
;

--		UNION


;

--COMMIT;


/*
