SET application_name = "SPONSO - statistiques 2/4";

-- insertion des nouvelles lignes dans la table finale de stats 
insert into sponsoring.statistiques_profil (
	statistiques_profil_identifiant,
	statistiques_profil_date_reception,
	statistiques_profil_date_livraison,
	statistiques_profil_site,
	statistiques_profil_campagne,
	statistiques_profil_etat,
	statistiques_profil_eligible,
	statistiques_profil_cout_annonceur,
	statistiques_profil_remuneration_affilie,
	statistiques_profil_total
)
select 
	t.statistiques_profil_travail_identifiant,
	t.statistiques_profil_travail_date_reception,
	t.statistiques_profil_travail_date_livraison,
	t.statistiques_profil_travail_site,
	t.statistiques_profil_travail_campagne,
	t.statistiques_profil_travail_etat,
	t.statistiques_profil_travail_eligible,
	t.statistiques_profil_travail_cout_annonceur,
	t.statistiques_profil_travail_remuneration_affilie,
	t.statistiques_profil_travail_total
from sponsoring.statistiques_profil_travail t
left outer join sponsoring.statistiques_profil p 
	on t.statistiques_profil_travail_identifiant = p.statistiques_profil_identifiant
where p.statistiques_profil_identifiant is null;
