Skip site navigation (1) Skip section navigation (2)

Re: Sum sets of records

From: "Bart Degryse" <Bart(dot)Degryse(at)indicator(dot)be>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Sum sets of records
Date: 2007-02-12 15:46:24
Message-ID: 45D099E0.A3DD.0030.0@indicator.be (view raw or flat)
Thread:
Lists: pgsql-sql
select sum(case when id = 'C' then value else -value end) as total
from mytable

>>> "Ezequias Rodrigues da Rocha" <ezequias(dot)rocha(at)gmail(dot)com> 2007-02-12 16:41 >>>
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

In response to

pgsql-sql by date

Next:From: Sylvain BarretteDate: 2007-02-12 15:59:18
Subject: RE : Sum sets of records
Previous:From: Ezequias Rodrigues da RochaDate: 2007-02-12 15:41:10
Subject: Sum sets of records

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group