pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Sum sets of records
2+ messages / 2 participants
[nested] [flat]

* Sum sets of records
@ 2007-02-12 15:41 Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
  2007-02-12 15:46 ` Re: Sum sets of records Bart Degryse <Bart.Degryse@indicator.be>
  0 siblings, 1 reply; 2+ messages in thread

From: Ezequias Rodrigues da Rocha @ 2007-02-12 15:41 UTC (permalink / raw)
  To: pgsql-sql

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

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Sum sets of records
  2007-02-12 15:41 Sum sets of records Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
@ 2007-02-12 15:46 ` Bart Degryse <Bart.Degryse@indicator.be>
  0 siblings, 0 replies; 2+ messages in thread

From: Bart Degryse @ 2007-02-12 15:46 UTC (permalink / raw)
  To: pgsql-sql

select sum(case when id = 'C' then value else -value end) as total
from mytable

>>> "Ezequias Rodrigues da Rocha" <ezequias.rocha@gmail.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

^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2007-02-12 15:46 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-02-12 15:41 Sum sets of records Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
2007-02-12 15:46 ` Bart Degryse <Bart.Degryse@indicator.be>

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