Re: two sums in one query

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: PFC <lists(at)boutiquenumerique(dot)com>
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 15:55:50
Message-ID: 20050708155550.GA28683@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Fri, Jul 08, 2005 at 16:49:44 +0200,
PFC <lists(at)boutiquenumerique(dot)com> wrote:
>
> >>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...

You aren't likely to see a significant speed up in that case either.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Steve Wampler 2005-07-08 16:00:05 Re: Make COUNT(*) Faster?
Previous Message Rod Taylor 2005-07-08 15:38:31 Re: Make COUNT(*) Faster?