You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

43 lines
2.1 KiB

src: |
SELECT min(p_calendrier.date) AS date,
p_calendrier_mois.annee::text AS texte,
min(p_calendrier.mois::text) AS alias,
min(p_calendrier.mois)::numeric(6,0) AS mois,
'1'::text AS level,
max(p_calendrier.mois)::numeric(6,0) AS tri1,
'1962-04-18'::date AS tri2
FROM base.p_calendrier,
base.p_calendrier_mois,
( SELECT to_number(substr(max(p_chiffrier.mois)::text, 1, 4) || '12'::text, '000000'::text) AS max_mois,
to_number(substr(min(p_chiffrier.mois)::text, 1, 4) || '01'::text, '000000'::text) AS min_mois
FROM activite.p_chiffrier) bornes
WHERE p_calendrier.mois >= bornes.min_mois AND p_calendrier.mois <= bornes.max_mois AND p_calendrier.mois = p_calendrier_mois.mois
GROUP BY p_calendrier_mois.annee
UNION ALL
SELECT p_calendrier.date,
p_calendrier_mois.texte,
p_calendrier.mois::text AS alias,
p_calendrier.mois,
'2'::text AS level,
p_calendrier.mois AS tri1,
'1962-04-18'::date AS tri2
FROM base.p_calendrier,
base.p_calendrier_mois,
( SELECT to_number(substr(max(p_chiffrier.mois)::text, 1, 4) || '12'::text, '000000'::text) AS max_mois,
to_number(substr(min(p_chiffrier.mois)::text, 1, 4) || '01'::text, '000000'::text) AS min_mois
FROM activite.p_chiffrier) bornes
WHERE p_calendrier.mois >= bornes.min_mois AND p_calendrier.mois <= bornes.max_mois AND p_calendrier.mois = p_calendrier_mois.mois AND substr(p_calendrier.date::text, 9, 2) = '01'::bpchar::text
UNION ALL
SELECT p_calendrier.date,
p_calendrier.texte,
''::text AS alias,
p_calendrier.mois,
'3'::text AS level,
p_calendrier.mois AS tri1,
p_calendrier.date AS tri2
FROM base.p_calendrier,
( SELECT to_number(substr(max(p_chiffrier.mois)::text, 1, 4) || '12'::text, '000000'::text) AS max_mois,
to_number(substr(min(p_chiffrier.mois)::text, 1, 4) || '01'::text, '000000'::text) AS min_mois
FROM activite.p_chiffrier) bornes
WHERE p_calendrier.mois >= bornes.min_mois AND p_calendrier.mois <= bornes.max_mois
ORDER BY 6 DESC, 7, 5;