|
|
src: |
|
|
|
SELECT p_calendrier.date,
|
|
|
p_calendrier_mois.texte ||
|
|
|
CASE
|
|
|
WHEN p_calendrier_mois.mois = bornes.max_mois_mat2a THEN ' - Dernier mois e-PMSI'::text
|
|
|
WHEN p_calendrier_mois.mois = bornes.max_mois_fildeleau THEN ' - Mois en cours'::text
|
|
|
ELSE ''::text
|
|
|
END AS texte,
|
|
|
'MT2A'::text AS alias,
|
|
|
p_calendrier.mois,
|
|
|
'1'::text AS level,
|
|
|
209901::numeric(6,0) AS tri1,
|
|
|
'1962-04-18'::date AS tri2
|
|
|
FROM base.p_calendrier,
|
|
|
base.p_calendrier_mois,
|
|
|
( SELECT max(
|
|
|
CASE
|
|
|
WHEN p_chiffrier.nb_rsa_champ_ghs <> 0::numeric THEN p_chiffrier.mois
|
|
|
ELSE 0::numeric
|
|
|
END) AS max_mois_mat2a,
|
|
|
max(p_chiffrier.mois) AS max_mois_fildeleau,
|
|
|
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 pmsi.p_chiffrier) bornes
|
|
|
WHERE p_calendrier.mois = bornes.max_mois_mat2a AND p_calendrier.mois = p_calendrier_mois.mois AND substr(p_calendrier.date::text, 9, 2) = '01'::text
|
|
|
UNION ALL
|
|
|
SELECT p_calendrier.date,
|
|
|
p_calendrier_mois.texte ||
|
|
|
CASE
|
|
|
WHEN p_calendrier_mois.mois = bornes.max_mois_mat2a THEN ' - Dernier mois e-PMSI'::text
|
|
|
WHEN p_calendrier_mois.mois = bornes.max_mois_fildeleau THEN ' - Mois en cours'::text
|
|
|
ELSE ''::text
|
|
|
END AS texte,
|
|
|
'MT2A'::text AS alias,
|
|
|
p_calendrier.mois,
|
|
|
'1'::text AS level,
|
|
|
209912::numeric(6,0) AS tri1,
|
|
|
'1962-04-18'::date AS tri2
|
|
|
FROM base.p_calendrier,
|
|
|
base.p_calendrier_mois,
|
|
|
( SELECT max(
|
|
|
CASE
|
|
|
WHEN p_chiffrier.nb_rsa_champ_ghs <> 0::numeric THEN p_chiffrier.mois
|
|
|
ELSE 0::numeric
|
|
|
END) AS max_mois_mat2a,
|
|
|
max(p_chiffrier.mois) AS max_mois_fildeleau,
|
|
|
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 pmsi.p_chiffrier) bornes
|
|
|
WHERE p_calendrier.mois = bornes.max_mois_fildeleau AND p_calendrier.mois <> bornes.max_mois_mat2a AND p_calendrier.mois = p_calendrier_mois.mois AND substr(p_calendrier.date::text, 9, 2) = '01'::text
|
|
|
UNION ALL
|
|
|
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 pmsi.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 ||
|
|
|
CASE
|
|
|
WHEN p_calendrier_mois.mois = bornes.max_mois_mat2a THEN ' - Dernier mois e-PMSI'::text
|
|
|
WHEN p_calendrier_mois.mois = bornes.max_mois_fildeleau THEN ' - Mois en cours'::text
|
|
|
ELSE ''::text
|
|
|
END AS 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 max(
|
|
|
CASE
|
|
|
WHEN p_chiffrier.nb_rsa_champ_ghs <> 0::numeric THEN p_chiffrier.mois
|
|
|
ELSE 0::numeric
|
|
|
END) AS max_mois_mat2a,
|
|
|
max(p_chiffrier.mois) AS max_mois_fildeleau,
|
|
|
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 pmsi.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'::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 pmsi.p_chiffrier) bornes
|
|
|
WHERE p_calendrier.mois >= bornes.min_mois AND p_calendrier.mois <= bornes.max_mois
|
|
|
ORDER BY 6 DESC, 7, 5;
|