Re: two sums in one query

From: PFC <lists(at)boutiquenumerique(dot)com>
To: "Bruno Wolff III" <bruno(at)wolff(dot)to>
Cc: "Kenneth Gonsalves" <lawgon(at)thenilgiris(dot)com>, "Ramakrishnan Muralidharan" <ramakrishnanm(at)pervasive-postgres(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: two sums in one query
Date: 2005-07-08 14:49:44
Message-ID: op.stlng6uhth1vuj@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


>> 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...

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Steve Wampler 2005-07-08 15:07:27 Re: Make COUNT(*) Faster?
Previous Message Bruno Wolff III 2005-07-08 14:35:08 Re: Make COUNT(*) Faster?