RE : Sum sets of records

From: Sylvain Barrette <sylvain(at)remax-quebec(dot)com>
To: 'Ezequias Rodrigues da Rocha' <ezequias(dot)rocha(at)gmail(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: RE : Sum sets of records
Date: 2007-02-12 15:59:18
Message-ID: 00c301c74ebe$c094abb0$1e01a8c0@fdpr.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Ezequias Rodrigues da Rocha 2007-02-12 17:43:14 Deadlock on transaction
Previous Message Bart Degryse 2007-02-12 15:46:24 Re: Sum sets of records