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 1D88652995 for ; Fri, 8 Jul 2005 04:36:04 -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 50210-03 for ; Fri, 8 Jul 2005 07:35:55 +0000 (GMT) Received: from sharp.noc24x7.com (unknown [69.56.128.138]) by svr1.postgresql.org (Postfix) with ESMTP id 83F4B529BC for ; Fri, 8 Jul 2005 04:35:54 -0300 (ADT) Received: from [61.3.110.136] (helo=thenilgiris.web) by sharp.noc24x7.com with esmtp (Exim 4.50) id 1DqnOv-0006Lm-F6; Fri, 08 Jul 2005 13:05:58 +0530 Received: by thenilgiris.web (Postfix, from userid 500) id 4BB025B91C; Fri, 8 Jul 2005 13:06:09 +0530 (IST) From: Kenneth Gonsalves To: "Ramakrishnan Muralidharan" Subject: Re: two sums in one query Date: Fri, 8 Jul 2005 13:06:08 +0530 User-Agent: KMail/1.6.1 Cc: References: <02767D4600E59A4487233B23AEF5C5992A4093@blrmail1.aus.pervasive.com> In-Reply-To: <02767D4600E59A4487233B23AEF5C5992A4093@blrmail1.aus.pervasive.com> MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <200507081306.08597.lawgon@thenilgiris.com> X-Antivirus-Scanner: Clean mail though you should still use an Antivirus X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - sharp.noc24x7.com X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - thenilgiris.com X-Source: X-Source-Args: X-Source-Dir: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.07 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200507/63 X-Sequence-Number: 22041 On Friday 08 Jul 2005 12:02 pm, Ramakrishnan Muralidharan wrote: > I have assuemed that the row will having eighter Debit account > or Credit account, the following Query will give sum of debit and > credit accounts > > SELECT SUM( CASE WHEN COALESCE( DEBIT , 0 ) <> 0 THEN =20 > COALESCE( AMOUNT , 0 ) ELSE 0 END ) AS DEBIT_AMT , SUM( CASE WHEN > COALESCE( CREDIT , 0 ) <> 0 THEN COALESCE( AMOUNT , 0 ) ELSE 0 > END ) AS CREDIT_AMT FROM actually, all the rows have both 'debit' and 'credit', but based on=20 the hint you gave i made this query which works: select sum(case when debit=3Daccount then amount else 0 end) as debtotal, sum(case when credit=3Daccount then amount else 0 end) as credtotal from voucherrows where debit =3D account or=20 credit =3D account thanks for taking the trouble - i never believed this was possible,=20 just asked on the off chance that it *may* be possible =2D-=20 regards kg http://www.livejournal.com/users/lawgon tally ho! http://avsap.org.in =E0=B2=87=E0=B2=82=E0=B2=A1=E0=B3=8D=E0=B2=B2=E0=B2=BF=E0=B2=A8=E0=B2=95=E0= =B3=8D=E0=B2=B8 =E0=AE=B5=E0=AE=BE=E0=AE=B4=E0=AF=8D=E0=AE=95!