CREATE TABLE spatial.v41002_gille_nbsp_pt AS (
SELECT gid,
	"ID",
	nb_sp,
	the_geom
FROM spatial.v41002_grille_250m
JOIN (SELECT id_maille,
		count(sp_dans_maille) AS nb_sp
	FROM (	SELECT 
			MIN(v41002_grille_250m."ID") AS id_maille,
			"ID" || "CODESP" AS sp_dans_maille
		FROM spatial.v41002_flore_pt, spatial.v41002_grille_250m
		WHERE st_intersects(spatial.v41002_flore_pt.the_geom, v41002_grille_250m.the_geom)
		GROUP BY("ID" || "CODESP")) AS ss_req
	GROUP BY (id_maille)
	) AS sss_req
ON v41002_grille_250m."ID"=sss_req.id_maille
ORDER BY "ID"
)