CREATE OR REPLACE VIEW pj_j_statut_j_sites AS
SELECT pg_j_rel.id_pg,
	pg_j_rel.pg_nom,
	pg_j_rel.pg_debut,
	pg_j_rel.pg_fin,
	pg_j_rel.statut,
	pg_j_rel.code_site,
	sites.libl_site,
	sites.code_ensemble
FROM (
	SELECT pg_j_statut.id_pg,
		pg_j_statut.pg_nom,
		pg_j_statut.pg_debut,
		pg_j_statut.pg_fin,
		pg_j_statut.statut,
		rel_site_pg.code_site
	FROM	(
		SELECT plan_gestion.id_pg,
			plan_gestion.pg_nom,
			plan_gestion.pg_debut,
			plan_gestion.pg_fin,
			lst_pgs_statut.statut
		FROM plan_gestion, lst_pgs_statut
		WHERE plan_gestion.pg_statut = lst_pgs_statut.id_statut
		) AS pg_j_statut
	JOIN rel_site_pg
	ON pg_j_statut.id_pg = rel_site_pg.id_pg) AS pg_j_rel
JOIN sites
ON pg_j_rel.code_site = sites.code_site;