-- View: vu_sites_niv1_statut

-- DROP VIEW vu_sites_niv1_statut;

CREATE OR REPLACE VIEW vu_sites_niv1_statut AS 
 SELECT sites_typo.objectid,
  sites_typo.code_site,
  sites_typo.libl_site,
  sites_typo.code_ensemble,
  sites_typo.site_ln,
  sites_typo.codesite_zabou,
  sites_typo.ref_statut,
  sites_typo.type_site,
  sit_liste_statut.id_statut,
  sit_liste_statut.ordre,
  sit_liste_statut.statut
   FROM (
	SELECT
	sites.objectid, 
	sites.code_site,
	sites.libl_site,
	sites.code_ensemble,
	sites.site_ln,
	sites.codesite_zabou,
	sites.ref_statut,
	sites.ref_typ_spe,
	sit_typologie.type_site
	FROM sites
	LEFT JOIN sit_typologie
	ON sites.ref_typ_spe = sit_typologie.id_site_spe_typ
	WHERE sites.ref_typ_spe=5)
	sites_typo
   JOIN sit_liste_statut
   ON sites_typo.ref_statut = sit_liste_statut.id_statut;

ALTER TABLE vu_sites_statuts OWNER TO postgres;
