X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id A90C452A62 for ; Fri, 8 Jul 2005 11:49:45 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 49790-03 for ; Fri, 8 Jul 2005 14:49:42 +0000 (GMT) Received: from boutiquenumerique.com (boutiquenumerique.com [82.67.9.10]) by svr1.postgresql.org (Postfix) with ESMTP id 9CEB252A06 for ; Fri, 8 Jul 2005 11:49:40 -0300 (ADT) Received: (qmail 26690 invoked from network); 8 Jul 2005 16:50:13 +0200 Received: from unknown (HELO localhost) (boutiquenumerique-lists@192.168.0.4) by boutiquenumerique.com with SMTP; 8 Jul 2005 16:50:13 +0200 To: "Bruno Wolff III" Cc: "Kenneth Gonsalves" , "Ramakrishnan Muralidharan" , pgsql-sql@postgresql.org Subject: Re: two sums in one query References: <02767D4600E59A4487233B23AEF5C5992A4093@blrmail1.aus.pervasive.com> <200507081306.08597.lawgon@thenilgiris.com> <20050708140725.GA22725@wolff.to> Message-ID: Date: Fri, 08 Jul 2005 16:49:44 +0200 From: PFC Organization: =?iso-8859-15?Q?La_Boutique_Num=E9rique?= Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-15 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit In-Reply-To: <20050708140725.GA22725@wolff.to> User-Agent: Opera M2/8.0 (Linux, build 1095) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.005 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200507/71 X-Sequence-Number: 22049 >> SELECT (SELECT sum(amount) FROM table WHERE debit=X) AS debit, (SELECT >> sum(amount) FROM table WHERE credit=x) AS credit; > > If most of the records are credits or debits you don't want to do this. > A single sequential scan through the table will be the best plan. I thought that debit = source account # and credit = dest account #, and there are a lot of different account...