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
;
"""