Re: Sum sets of records

Поиск
Список
Период
Сортировка
От Bart Degryse
Тема Re: Sum sets of records
Дата
Msg-id 45D099E0.A3DD.0030.0@indicator.be
обсуждение исходный текст
Ответ на Sum sets of records  ("Ezequias Rodrigues da Rocha" <ezequias.rocha@gmail.com>)
Список 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

В списке pgsql-sql по дате отправления:

Предыдущее
От: "Ezequias Rodrigues da Rocha"
Дата:
Сообщение: Sum sets of records
Следующее
От: Sylvain Barrette
Дата:
Сообщение: RE : Sum sets of records