X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id E3AD2D1B511 for ; Thu, 9 Oct 2003 17:16:57 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 78760-01 for ; Thu, 9 Oct 2003 14:16:11 -0300 (ADT) Received: from davinci.ethosmedia.com (unknown [209.128.84.228]) by svr1.postgresql.org (Postfix) with ESMTP id 6E8EAD1B528 for ; Thu, 9 Oct 2003 14:16:10 -0300 (ADT) Received: from [63.195.55.98] (HELO spooky) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 3746090; Thu, 09 Oct 2003 10:16:46 -0700 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Organization: Aglio Database Solutions To: Kurt Overberg , pgsql-sql@postgresql.org Subject: Re: Selecting rows as if they were columns? Date: Thu, 9 Oct 2003 10:14:09 -0700 User-Agent: KMail/1.4.3 References: <3F855F38.9070803@hotdogrecords.com> In-Reply-To: <3F855F38.9070803@hotdogrecords.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <200310091014.09695.josh@agliodbs.com> X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/104 X-Sequence-Number: 15504 Kurt, > I've got what I think should be a pretty simple problem- I just can't > figure out how I'd do it. Heck, I can't even figure out how I'd search > for an answer to this problem. This is an old common SQL problem ... the "crosstab" table. There are 3 standard ways to solve it, depending on the exact circumstances of your case. It's probably best if you buy Joe Celko's "SQL for Smarties, 2nd Ed.", which has a 50-page chapter on the topic and explores the methods in detail. -- Josh Berkus Aglio Database Solutions San Francisco