Re: Sorting items in aggregate function

Поиск
Список
Период
Сортировка
От Michael Fuhr
Тема Re: Sorting items in aggregate function
Дата
Msg-id 20060912181759.GA66966@winnie.fuhr.org
обсуждение исходный текст
Ответ на Sorting items in aggregate function  (Steven Murdoch <psql+Steven.Murdoch@cl.cam.ac.uk>)
Ответы Re: Sorting items in aggregate function
Список pgsql-sql
On Tue, Sep 12, 2006 at 04:46:28PM +0100, Steven Murdoch wrote:
> Here is an example of a setup and what I could like to achieve. Does
> anyone have suggestions on what is the best way to get the desired
> result?

Use the aggregate over an ordered subquery:

SELECT name, trim(concat(code || ' ')) AS codes
FROM ( SELECT a.name, b.code FROM a LEFT JOIN ab ON a.id = ab.a_id LEFT JOIN b ON ab.b_id = b.id ORDER BY b.code
) AS s
GROUP BY name
ORDER BY name;

Here's a comment from Tom Lane, one of the core developers, on
feeding the aggregate based on the subquery's order:

http://archives.postgresql.org/pgsql-general/2005-09/msg00047.php

-- 
Michael Fuhr


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

Предыдущее
От: Daryl Richter
Дата:
Сообщение: Re: Joint a table back on itself?
Следующее
От: "Aaron Bono"
Дата:
Сообщение: Re: on connect/on disconnect