From: Bart Degryse <Bart.Degryse@indicator.be>
To: pgsql-sql@postgresql.org
Subject: Re: Sum sets of records
Date: Mon, 12 Feb 2007 16:46:24 +0100
Message-ID: <45D099E0.A3DD.0030.0@indicator.be> (raw)
In-Reply-To: <55c095e90702120741w3908f730vbd23b6d9b4fa7cc3@mail.gmail.com>
References: <55c095e90702120741w3908f730vbd23b6d9b4fa7cc3@mail.gmail.com>
select sum(case when id = 'C' then value else -value end) as total
from mytable
>>> "Ezequias Rodrigues da Rocha" <ezequias.rocha@gmail.com> 2007-02-12 16:41 >>>
Hi list,
I would like a little help from you to get the sum value of various subsets of my table.
My table is like this
id | type | value
1 C 10.00
2 C 15.00
3 W 5.00
4 W 3.00
Where C is credit and w is witdraw.
How do I sum all records with C and subtract with all records with type W ?
Is it possible ?
Ezequias
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: Bart.Degryse@indicator.be
Subject: Re: Sum sets of records
In-Reply-To: <45D099E0.A3DD.0030.0@indicator.be>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox