pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Sylvain Barrette <sylvain@remax-quebec.com>
To: Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
To: pgsql-sql@postgresql.org
Subject: RE : Sum sets of records
Date: Mon, 12 Feb 2007 10:59:18 -0500
Message-ID: <00c301c74ebe$c094abb0$1e01a8c0@fdpr.com> (raw)
In-Reply-To: <55c095e90702120741w3908f730vbd23b6d9b4fa7cc3@mail.gmail.com>

Hi,

"Group by" is what you're looking for..

select type,sum(value) from MyTable group by type

Or for the total only

Select sum(case when type='C' then value when type='W' then -value else
0 end) from MyTable

hth


Sylvain Barrette
Architecte et  analyste principal,
RE/MAX Québec inc.


Hi list,

I would like a little help from you to get the sum value of various
subsets of my table.

My table is like this

id | type | value
1   C       10.00
2   C       15.00
3  W        5.00
4  W        3.00

Where C is credit and w is witdraw.

How do I sum all records with C and subtract with all records with type
W ?

Is it possible ?
Ezequias

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.411 / Virus Database: 268.17.36/681 - Release Date:
2007-02-11
 




Message-ID: <00c301c74ebe$c094abb0$1e01a8c0@fdpr.com>
Permalink:  ../00c301c74ebe$c094abb0$1e01a8c0@fdpr.com/
Also on:    postgresql.org/message-id/00c301c74ebe$c094abb0$1e01a8c0@fdpr.com

 · 

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: sylvain@remax-quebec.com, ezequias.rocha@gmail.com
  Subject: Re: RE : Sum sets of records
  In-Reply-To: <00c301c74ebe$c094abb0$1e01a8c0@fdpr.com>

* 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