More wacky grouping - Mailing list pgsql-sql

From James Taylor
Subject More wacky grouping
Date
Msg-id 002601c2fa41$3a88d760$4500a8c0@theplague
Whole thread Raw
Responses 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>)
List 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 by date:

Previous
From: Manfred Koizar
Date:
Subject: Re: can i make this sql query more efficiant?
Next
From: Josh Berkus
Date:
Subject: Re: More wacky grouping