From: cnliou@eurosport.com
To: pgsql-sql@postgresql.org
Subject: Group And Sort After Union
Date: 30 Jul 2002 01:46:22 -0700
Message-ID: <eaa50a08.0207300046.fd57ade@posting.google.com> (raw)
Greetings!
I want to GROUP BY and ORDER BY on the result of UNION similar to the
following (wrong) SQL:
(SELECT c11 AS c1,SUM(c12) AS c2 FROM table1
UNION
SELECT c21 AS c1,SUM(c22) AS c2 FROM table2
)
GROUP BY c1
ORDER BY c2;
Please note that the following is NOT what I want because it generates
2 groups of data set:
SELECT c11 AS c1,SUM(c12) AS c2 FROM table1
GROUP BY c1
ORDER BY c2
UNION
SELECT c21 AS c1,SUM(c22) AS c2 FROM table2
GROUP BY c1
ORDER BY c2;
How do I do that? Thank you in advance!
CNLIOU
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: cnliou@eurosport.com
Subject: Re: Group And Sort After Union
In-Reply-To: <eaa50a08.0207300046.fd57ade@posting.google.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