From: Theo Galanakis <Theo.Galanakis@lonelyplanet.com.au>
To: 'pgsql-sql@postgresql.org' <pgsql-sql@postgresql.org>
Subject: Re: CROSS-TAB query help? I have read it cant be done in on
Date: Tue, 17 Aug 2004 12:47:12 +1000
Message-ID: <82E30406384FFB44AFD1012BAB230B55037D0510@shiva.au.lpint.net> (raw)
Thanks Rickard
Max may not work as not all the data is numerical. However I will give the
contrib/cross-tab a go!
Theo
-----Original Message-----
From: Richard Huxton [mailto:dev@archonet.com]
Sent: Monday, 16 August 2004 6:06 PM
To: Theo Galanakis
Cc: 'pgsql-sql@postgresql.org'
Subject: Re: [SQL] CROSS-TAB query help? I have read it cant be done in one
SQL, pro ve them wrong!
Theo Galanakis wrote:
> Does anyone know how to perform a cross-tab query in ONE SQL without
> having to write a SP? The SQL at the end of this email attempts to
> display the subquery result-set in a cross-tab format, it does not
> group the content onto one row as it should in the sample below. SQL
> is below if it makes any sense, however the sub-query returns data as
> below.
>
> Examle:
>
> Name Value
> ID 1
> Cola 10
> Colb 20
> Colc 30
> Cold 40
> Cole 50
>
> I want to output as:
>
> ID, cola, colb, colb, cold, cole
> 1 10 30 30 40 50
> Actual Output:
>
> content_object_id | xpos | ypos | text | textangle |
texttype
> | symbol | linktype
> -------------------+------+------+-------------------+-----------+----
> -------------------+------+------+-------------------+-----------+----
> -------------------+------+------+-------------------+-----------+--
> 100473 | 93 | | | |
> 100473 | | 77 | | |
> 100473 | | | text1 | |
Don't forget the provided crosstab functions (in contrib/). If you don't
want that, you could aggregate your results:
SELECT content_object_id, MAX(xpos), MAX(ypos), ...
FROM (
<your query here>
) AS raw
GROUP BY content_object_id;
--
Richard Huxton
Archonet Ltd
______________________________________________________________________
This email, including attachments, is intended only for the addressee
and may be confidential, privileged and subject to copyright. If you
have received this email in error, please advise the sender and delete
it. If you are not the intended recipient of this email, you must not
use, copy or disclose its content to anyone. You must not copy or
communicate to others content that is confidential or subject to
copyright, unless you have the consent of the content owner.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: Theo.Galanakis@lonelyplanet.com.au
Subject: Re: CROSS-TAB query help? I have read it cant be done in on
In-Reply-To: <82E30406384FFB44AFD1012BAB230B55037D0510@shiva.au.lpint.net>
References: <82E30406384FFB44AFD1012BAB230B55037D0510@shiva.au.lpint.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox