1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| (SELECT
t.code_famille AS "Code Famille",
t.texte_famille AS "Texte Famille",
COUNT(t.*) AS Nombre,
SUM(t.montant) AS Montant,
round(sum(t.montant)/(select sum(montant)/100 from test),2) as "%/Total",
(t1.montant_trim_1) AS "Montant 1er trimestre",
(t2.montant_trim_2) AS "Montant 2eme trimestre",
(t3.montant_trim_3) AS "Montant 3eme trimestre",
(t4.montant_trim_4) AS "Montant 4eme trimestre"
FROM test t
LEFT OUTER JOIN
(
SELECT code_famille,
SUM(montant) AS montant_trim_1
FROM test
WHERE (EXTRACT(MONTH FROM date) BETWEEN 1 AND 3)
GROUP BY code_famille
) AS t1 ON t1.code_famille = t.code_famille
LEFT OUTER JOIN
(
SELECT code_famille,
SUM(montant) AS montant_trim_2
FROM test
WHERE (EXTRACT(MONTH FROM date) BETWEEN 4 AND 6)
GROUP BY code_famille
) AS t2 ON t2.code_famille = t.code_famille
...
GROUP BY t.code_famille, t.texte_famille, t1.montant_trim_1, t2.montant_trim_2, t3.montant_trim_3, t4.montant_trim_4
ORDER BY SUM(t.montant) DESC) |
Partager