Re: two sums in one query - Mailing list pgsql-sql

From Bruno Wolff III
Subject Re: two sums in one query
Date
Msg-id 20050708155550.GA28683@wolff.to
Whole thread Raw
In response to Re: two sums in one query  (PFC <lists@boutiquenumerique.com>)
List pgsql-sql
On Fri, Jul 08, 2005 at 16:49:44 +0200, PFC <lists@boutiquenumerique.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.


pgsql-sql by date:

Previous
From: Rod Taylor
Date:
Subject: Re: Make COUNT(*) Faster?
Next
From: Steve Wampler
Date:
Subject: Re: Make COUNT(*) Faster?