Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 7F0449FB5FA for ; Mon, 12 Feb 2007 11:47:08 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-new, port 10024) with ESMTP id 70768-09 for ; Mon, 12 Feb 2007 11:46:32 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from interscan.indicator.com (mail.indicator.be [193.121.199.3]) by postgresql.org (Postfix) with ESMTP id E5CDD9FB2A0 for ; Mon, 12 Feb 2007 11:46:37 -0400 (AST) Received: from webaccess.indicator.be ([10.100.1.7]) by interscan.indicator.com with InterScan Message Security Suite; Mon, 12 Feb 2007 16:34:36 +0100 Received: from DOMEXT-MTA by webaccess.indicator.bewith Novell_GroupWise; Mon, 12 Feb 2007 16:46:35 +0100 Message-Id: <45D099E0.A3DD.0030.0@indicator.be> X-Mailer: Novell GroupWise Internet Agent 7.0.1 Date: Mon, 12 Feb 2007 16:46:24 +0100 From: "Bart Degryse" To: Subject: Re: Sum sets of records References: <55c095e90702120741w3908f730vbd23b6d9b4fa7cc3@mail.gmail.com> In-Reply-To: <55c095e90702120741w3908f730vbd23b6d9b4fa7cc3@mail.gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="=__PartB6922EC0.0__=" X-imss-version: 2.046 X-imss-result: Passed X-imss-approveListMatch: *@indicator.be X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.272 tagged_above=0 required=5 tests=BAYES_50, FORGED_RCVD_HELO, HTML_50_60, HTML_MESSAGE, UNPARSEABLE_RELAY X-Spam-Level: X-Archive-Number: 200702/139 X-Sequence-Number: 27473 --=__PartB6922EC0.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable select sum(case when id =3D 'C' then value else -value end) as total from mytable >>> "Ezequias Rodrigues da Rocha" 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 --=__PartB6922EC0.0__= Content-Type: text/html; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Description: HTML
select sum(case when id =3D 'C' then value else -value end) as = total
from mytable

>>> "Ezequias Rodrigues da Rocha" <ezequias.rocha@gmai= l.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 &nbs= p; C       10.00
2   C &nbs= p;     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

--=__PartB6922EC0.0__=--