More wacky grouping

Поиск
Список
Период
Сортировка
От James Taylor
Тема More wacky grouping
Дата
Msg-id 002601c2fa41$3a88d760$4500a8c0@theplague
обсуждение исходный текст
Ответы Re: More wacky grouping  (Josh Berkus <josh@agliodbs.com>)
Re: More wacky grouping  (Joe Conway <mail@joeconway.com>)
Re: More wacky grouping  (Manfred Koizar <mkoi-pg@aon.at>)
Список pgsql-sql
I need to do grouping based on various aggregates, but the way my table
is set up (it can't change) is making things kind of difficult.

My table looks something like this:

Id | id_customer | id_datatype | content
----------------------------------------
1  | 25          | 1           | John
2  | 25          | 2           | Globochem
3  | 25          | 3           | 845.92
4  | 26          | 1           | Patty
5  | 26          | 2           | Globochem
6  | 26          | 3           | 284.92
7  | 27          | 1           | Sam
8  | 27          | 2           | Toxichem
9  | 27          | 3           | 1239.47

Datatype 1 = Name, 2 = Company, 3 = account balance.

I need to do an aggregate function on content where id_datatype = 3, and
then group by content where id_datatype = 2

So, say I wanted to do a sum function, it would end up with something
like:

Company   | Sum
-------------------
Globochem | 1130.84
Toxichem  | 1239.47


The content isn't static, so I can't use static names for content in the
query.

Any ideas on this one?



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

Предыдущее
От: Manfred Koizar
Дата:
Сообщение: Re: can i make this sql query more efficiant?
Следующее
От: Josh Berkus
Дата:
Сообщение: Re: More wacky grouping