Group And Sort After Union

Поиск
Список
Период
Сортировка
От cnliou@eurosport.com (cnliou)
Тема Group And Sort After Union
Дата
Msg-id eaa50a08.0207300046.fd57ade@posting.google.com
обсуждение исходный текст
Ответы Re: Group And Sort After Union  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-sql
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


В списке pgsql-sql по дате отправления:

Предыдущее
От: Ken Corey
Дата:
Сообщение: Re: Returning PK of first insert for second insert use.
Следующее
От: "Chad R. Larson"
Дата:
Сообщение: Re: [ADMIN] 3-tier