From ba3876d42b071ce4a3e4b2b1822e984813edb481 Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Thu, 8 Oct 2015 22:25:20 +0200 Subject: [PATCH] =?utf8?q?[bde]=20transactions=20:=20ajout=20du=20solde=20?= =?utf8?q?apr=C3=A8s=20transaction?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit soldes cumulés croissants avec OVER Attention au special case emetteur == destinataire… --- bde/transactions.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bde/transactions.sh b/bde/transactions.sh index f214085..088ec5c 100755 --- a/bde/transactions.sh +++ b/bde/transactions.sh @@ -5,7 +5,9 @@ export LESS='-S' psql note -c " - SELECT t.id,t.date,t.quantite,t.montant,t.description,t.valide,t.emetteur,t.destinataire, + SELECT t.id, t.date, + sum((CASE WHEN $1 = emetteur THEN (CASE WHEN $1 = destinataire THEN 0 ELSE -1 END) ELSE 1 END)*montant*quantite) OVER (ORDER BY date ASC) AS soldeapres, + t.quantite, t.montant, t.description, t.valide, t.emetteur, t.destinataire, adhe.pseudo AS emetteur, adhd.pseudo AS destinataire FROM transactions AS t, comptes AS adhe, comptes AS adhd WHERE $1 in (emetteur, destinataire) AND t.emetteur=adhe.idbde AND t.destinataire=adhd.idbde AND valide -- 2.39.2