X-Original-To: pgsql-sql@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id F09F0474E44 for ; Thu, 3 Apr 2003 19:29:27 -0500 (EST) Received: from pimout1-ext.prodigy.net (pimout1-ext.prodigy.net [207.115.63.77]) by postgresql.org (Postfix) with ESMTP id ED6FB474E42 for ; Thu, 3 Apr 2003 19:28:55 -0500 (EST) Received: from theplague (adsl-66-126-110-160.dsl.lsan03.pacbell.net [66.126.110.160]) by pimout1-ext.prodigy.net (8.12.3 patch/8.12.3) with ESMTP id h340SjBp026344 for ; Thu, 3 Apr 2003 19:28:57 -0500 From: "James Taylor" To: Subject: More wacky grouping Date: Thu, 3 Apr 2003 16:29:08 -0800 Message-ID: <002601c2fa41$3a88d760$4500a8c0@theplague> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.2616 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Importance: Normal X-Spam-Status: No, hits=0.0 required=5.0 tests=none version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/57 X-Sequence-Number: 12758 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?