Crosstab-style query in pure SQL - Mailing list pgsql-sql

From dev@archonet.com
Subject Crosstab-style query in pure SQL
Date
Msg-id 1493.192.168.1.16.1042462021.squirrel@mainbox.archonet.com
Whole thread Raw
Responses Re: Crosstab-style query in pure SQL  ("Josh Berkus" <josh@agliodbs.com>)
List pgsql-sql
TIA all

I have a table containing milestones achieved for projects, marked as
being in particular quarters.

CREATE TABLE milestones (   proj_id     int4,   sortorder   SERIAL,   qtr         int4,   description varchar(200)
);

Now I need the milestone descriptions output across the page like: proj_id | q1 | q2 | q3 | q4
and sorted according to "sortorder".

Judicious use of CASE can get me the quarterly columns but I need to
eliminate holes. Any clever ideas without resorting to procedural
solutions (either table function or application code)?

TIA

- Richard Huxton


pgsql-sql by date:

Previous
From: dev@archonet.com
Date:
Subject: Re: Unique indexes not unique?
Next
From: Tom Lane
Date:
Subject: Re: Unique indexes not unique?