Search Postgresql Archives

Re: Aggregates, group, and order by

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Monday, November 07, 2005 12:12 AM
Michael Glaesemann wrote:
> 
> select bar_id, array_accum(foo_value)
> from ordered_foo
> group by bar_id
> order by bar_id;
> bar_id |         array_accum
> --------+-----------------------------
>        1 | {delta,alpha,charlie,bravo}
>        2 | {C,B,A,D}
> 
> 
> The result I'd like to see is
> bar_id |         array_accum
> --------+-----------------------------
>        1 | {alpha,bravo,charlie,delta}
>        2 | {A,B,C,D}
 
select bar_id, array_accum(foo_value)
from 
(SELECT * FROM ordered_foo ORDER BY foo_pos) foo
group by bar_id
order by bar_id;

bar_id,array_accum
1,{alpha,bravo,charlie,delta}
2,{A,B,C,D}

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

               http://archives.postgresql.org


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux