From c19278d817c4905042175dfcef5ac8965410acad Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Sat, 14 Feb 2015 18:17:01 +0100 Subject: [PATCH] [depenses.py] Useless inception --- bde/stats/depenses.py | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/bde/stats/depenses.py b/bde/stats/depenses.py index 787a668..1997d4c 100755 --- a/bde/stats/depenses.py +++ b/bde/stats/depenses.py @@ -9,23 +9,21 @@ import psycopg2.extras import sys create_temp_table = """ - SELECT * + SELECT extract(year FROM date) AS annee, + CAST(sum( + CASE WHEN emetteur = %(idbde)s THEN montant * quantite + ELSE 0 + END + )/100.0 AS numeric(10,2)) AS depenses, + CAST(sum( + CASE WHEN destinataire = %(idbde)s THEN montant*quantite + ELSE 0 + END + )/100.0 AS numeric(10,2)) AS gains INTO past - FROM - (SELECT extract(year FROM date) AS annee, - CAST(sum( - CASE WHEN emetteur = %(idbde)s THEN montant * quantite - ELSE 0 - END - )/100.0 AS numeric(10,2)) AS depenses, - CAST(sum( - CASE WHEN destinataire = %(idbde)s THEN montant*quantite - ELSE 0 - END - )/100.0 AS numeric(10,2)) AS gains - FROM transactions - WHERE valide AND %(idbde)s in (emetteur, destinataire) - GROUP BY annee) AS pif + FROM transactions + WHERE valide AND %(idbde)s in (emetteur, destinataire) + GROUP BY annee ; """ -- 2.39.2