pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Joel Burton <joel@joelburton.com>
To: Robert Wynter <rgwynter@rci.rogers.com>
To: pgsql-sql@postgresql.org
Subject: Re: union query format
Date: Fri, 26 Apr 2002 17:32:14 -0400
Message-ID: <JGEPJNMCKODMDHGOBKDNIEHBCLAA.joel@joelburton.com> (raw)
In-Reply-To: <44586AAA5ECBD511A6520004AC2589A652D81F@rssesnexg.rogers.com>

> Hi I'm trying to combine 3 query's in a union query as follows:
>
> rowdate		nco	nca	nch	aht	asa	svl
> 	%abandon
>
> With Query 1;
>
> 04/01/02	1000	500	500	450	23	.23	.50
> 04/02/02	2000	500	1500	450	23	.23	.50
>
> plus Query 2;
>
> wtd		3000	1000	2000	450	23	.23	.50
>
> and Query 3;
>
> mtd		3000	1000	2000	450	23	.23	.50
>
>
> I have 2 problems once the Union Query has run.
> 1.	because Query 2 & 3 are text, it's forcing Query 1 into text and the
> date order is all messed up.
> 2. I need to formate  the fileds for svl & % abandon as a percentage.

Something like:

SELECT rowdate AS sort, rowdate::text, nco, ..., asa * 100 || '%' FROM
query1
   UNION
SELECT 'infinity'::timestamp, rowdate, ... FROM query2
  UNION
SELECT 'infinity'::timestamp, rowdate, ... FROM query2
ORDER BY 1

This will let you sort by the first column as dates (keeping wtd and mtd at
the end).
To show a number as percentage, x * 100 appended with '%' works fine. See
to_char() if you need more control.




view thread (3+ messages)

Message-ID: <JGEPJNMCKODMDHGOBKDNIEHBCLAA.joel@joelburton.com>
Permalink:  ../JGEPJNMCKODMDHGOBKDNIEHBCLAA.joel@joelburton.com/
Also on:    postgresql.org/message-id/JGEPJNMCKODMDHGOBKDNIEHBCLAA.joel@joelburton.com

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: joel@joelburton.com, rgwynter@rci.rogers.com
  Subject: Re: union query format
  In-Reply-To: <JGEPJNMCKODMDHGOBKDNIEHBCLAA.joel@joelburton.com>

* 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