pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruno Wolff III <bruno@wolff.to>
To: PFC <lists@boutiquenumerique.com>
Cc: Kenneth Gonsalves <lawgon@thenilgiris.com>
Cc: Ramakrishnan Muralidharan <ramakrishnanm@pervasive-postgres.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: two sums in one query
Date: Fri, 8 Jul 2005 10:55:50 -0500
Message-ID: <20050708155550.GA28683@wolff.to> (raw)
In-Reply-To: <op.stlng6uhth1vuj@localhost>
References: <02767D4600E59A4487233B23AEF5C5992A4093@blrmail1.aus.pervasive.com>
	<200507081306.08597.lawgon@thenilgiris.com>
	<op.stlkoiq4th1vuj@localhost>
	<20050708140725.GA22725@wolff.to>
	<op.stlng6uhth1vuj@localhost>

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.



view thread (7+ messages)

Message-ID: <20050708155550.GA28683@wolff.to>
Permalink:  ../20050708155550.GA28683@wolff.to/
Also on:    postgresql.org/message-id/20050708155550.GA28683@wolff.to

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: bruno@wolff.to, lists@boutiquenumerique.com, lawgon@thenilgiris.com, ramakrishnanm@pervasive-postgres.com
  Subject: Re: two sums in one query
  In-Reply-To: <20050708155550.GA28683@wolff.to>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox