-- View: mf.vu_actes_par_site

-- DROP VIEW mf.vu_actes_par_site;

CREATE OR REPLACE VIEW mf.vu_actes_par_site AS 
 SELECT join3.code_site, join3.code_acte, join3.type_acte, join3.type_maitrise, acte.date_acte, acte.nom_notaire, acte.prix_acquisition, acte.origine_propriete, acte.duree_conv, acte.echeance_prevue
   FROM ( SELECT DISTINCT ON (parcelle.code_site, join2.code_acte) parcelle.code_site, join2.code_acte, join2.type_acte, join2.type_maitrise
           FROM ( SELECT join1.code_acte, join1.type_acte, type_maitrise.type_maitrise
                   FROM ( SELECT acte.code_acte, type_acte.type_acte, acte.ref_type_maitrise
                           FROM mf.acte
                      LEFT JOIN mf.type_acte ON acte.ref_type_acte = type_acte.id_type_acte) join1
              LEFT JOIN mf.type_maitrise ON join1.ref_type_maitrise = type_maitrise.id_type_maitrise) join2
      JOIN mf.parcelle ON parcelle.code_acte::text = join2.code_acte::text) join3
   JOIN mf.acte ON acte.code_acte::text = join3.code_acte::text;

ALTER TABLE mf.vu_actes_par_site OWNER TO ludodo;
GRANT ALL ON TABLE mf.vu_actes_par_site TO ludodo;
GRANT SELECT, REFERENCES, TRIGGER ON TABLE mf.vu_actes_par_site TO public;
GRANT SELECT, REFERENCES, TRIGGER ON TABLE mf.vu_actes_par_site TO cpnrc;
