Skip to content

Instantly share code, notes, and snippets.

@Djourdain
Created June 23, 2022 08:43
Show Gist options
  • Save Djourdain/e84e0e42eb146af4d1652a4db0b893f9 to your computer and use it in GitHub Desktop.
Save Djourdain/e84e0e42eb146af4d1652a4db0b893f9 to your computer and use it in GitHub Desktop.
WITH FAMILLE_SAUVE AS(
SELECT cdfam, MAX(cdmaj) AS cdmaj, MAX(dtsave)
FROM ever_famille_sauve
WHERE dtsave >= :dateDernierTraitement
GROUP BY cdfam
)
SELECT efs.cdfam as code_famille,
f.libfam as libelle_famille,
m.id_centre_profit AS centre_profit,
efs.cdmaj = 'S' AS a_supprimer
FROM FAMILLE_SAUVE efs
INNER JOIN famille f
ON f.cdfam = efs.cdfam
AND f.dtann IS NULL
AND f.cdfam IS NOT NULL
INNER JOIN mapping_centre_profit_famille m
ON m.cdcategfam = f.cdcategfam
AND m.id_centre_profit IS NOT NULL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment