More wacky grouping

From: "James Taylor" <jtx(at)hatesville(dot)com>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: More wacky grouping
Date: 2003-04-04 00:29:08
Message-ID: 002601c2fa41$3a88d760$4500a8c0@theplague
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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?

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Josh Berkus 2003-04-04 00:42:16 Re: More wacky grouping
Previous Message Manfred Koizar 2003-04-03 23:13:18 Re: can i make this sql query more efficiant?