CREATE OR REPLACE VIEW vu_fds_event_export_bilan_annuel AS 

/* jointure avec les partenaires */
SELECT	join_themes.*,
		vu_fds_event_partenaires.partenaires,
		vu_fds_event_partenaires.nb_partenaires
FROM vu_fds_event_partenaires
	RIGHT JOIN (
	/* jointure avec les thèmes */
	SELECT	join_nivsco.*,
			vu_fds_event_themes.themes,
			vu_fds_event_themes.nb_themes
	FROM vu_fds_event_themes
	RIGHT JOIN (
		/* jointure avec les niveaux scolaires */
		select	vu_fds_event_alljoin_details.*,
			vu_fds_event_etablis_sco.typ_etablissements,
			vu_fds_event_etablis_sco.nb_typ_etablis
		from	vu_fds_event_alljoin_details
		LEFT JOIN vu_fds_event_etablis_sco
		ON  vu_fds_event_alljoin_details.num_evenement=vu_fds_event_etablis_sco.num_evenement) AS join_nivsco
	ON join_nivsco.num_evenement = vu_fds_event_themes.num_evenement) AS join_themes
ON join_themes.num_evenement = vu_fds_event_partenaires.num_evenement
;

ALTER TABLE vu_fds_event_etablis_sco
  OWNER TO postgres;
GRANT ALL ON TABLE vu_vds_event_alljoin TO postgres;
GRANT SELECT, INSERT, REFERENCES, TRIGGER ON TABLE vu_vds_event_alljoin TO public;