Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 5260F9FB624 for ; Mon, 12 Feb 2007 13:40:33 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-new, port 10024) with ESMTP id 95856-03 for ; Mon, 12 Feb 2007 13:40:26 -0400 (AST) X-Greylist: delayed 01:41:06.239614 by SQLgrey-1.7.4 Received: from falla.videotron.net (falla.videotron.net [205.151.222.106]) by postgresql.org (Postfix) with ESMTP id C5C7D9FB619 for ; Mon, 12 Feb 2007 13:40:26 -0400 (AST) Received: from xp1600 ([207.96.182.243]) by falla.videotron.net (Sun Internet Mail Server sims.3.5.2000.03.23.18.03.p10) with ESMTP id <0JDC00HF4XQUI1@falla.videotron.net> for pgsql-sql@postgresql.org; Mon, 12 Feb 2007 10:59:18 -0500 (EST) Date: Mon, 12 Feb 2007 10:59:18 -0500 From: Sylvain Barrette Subject: RE : Sum sets of records In-reply-to: <55c095e90702120741w3908f730vbd23b6d9b4fa7cc3@mail.gmail.com> To: 'Ezequias Rodrigues da Rocha' , pgsql-sql@postgresql.org Message-id: <00c301c74ebe$c094abb0$1e01a8c0@fdpr.com> MIME-version: 1.0 X-Mailer: Microsoft Outlook, Build 10.0.2627 Content-type: text/plain; charset=iso-8859-1 Content-transfer-encoding: quoted-printable Importance: Normal X-MSMail-Priority: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028 X-Priority: 3 (Normal) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=BAYES_50 X-Spam-Level: X-Archive-Number: 200702/140 X-Sequence-Number: 27474 Hi, "Group by" is what you're looking for.. select type,sum(value) from MyTable group by type Or for the total only Select sum(case when type=3D'C' then value when type=3D'W' then -value = else 0 end) from MyTable hth Sylvain Barrette Architecte et analyste principal, RE/MAX Qu=E9bec inc. 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 --=20 No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.1.411 / Virus Database: 268.17.36/681 - Release Date: 2007-02-11 =20