Re: [GENERAL] Grouping, Aggregate, Min, Max

2013-12-16 Thread Misa Simic
2013/12/13 Kevin Grittner > Misa Simic wrote: > > > So I wonder - is there some kind of aggregate window function > > what does desired results? > > Not built in, but PostgreSQL makes it pretty easy to do so. With a > little effort to define your own aggregate function, your query can > look li

Re: [GENERAL] Grouping, Aggregate, Min, Max

2013-12-13 Thread Kevin Grittner
Misa Simic wrote: > So I wonder - is there some kind of aggregate window function > what does desired results? Not built in, but PostgreSQL makes it pretty easy to do so.  With a little effort to define your own aggregate function, your query can look like this: SELECT     thing_id,     categor

Re: [GENERAL] Grouping, Aggregate, Min, Max

2013-12-13 Thread David Johnston
Re:custom aggregate: I'd probably try building a two dimensional array in the state transition function. Take the new value and check if it is adjacent to the last value in the last bin of the current state. If so add it to that bin. If not create a new bin and store it there. Requires sorted i

Re: [GENERAL] Grouping, Aggregate, Min, Max

2013-12-13 Thread Misa Simic
Thanks Rémi-C, Well, not sure is it a goal to avoid aggregates... Bellow problem/solution even works (not sure) I guess would produce (if we imagine instead of count it use min and max in a row, though this case a bit complicated because of it should take real values from the source table, becaus

Re: [GENERAL] Grouping, Aggregate, Min, Max

2013-12-13 Thread Rémi Cura
There is a trick to simplify the thing and avoid using aggregates : I think it will give you your answer. http://postgresql.1045698.n5.nabble.com/Count-of-records-in-a-row-td5775363i20.html Cheers, Rémi-C 2013/12/13 Misa Simic > Hi All, > > I am not sure how to define with words what I want t

[GENERAL] Grouping, Aggregate, Min, Max

2013-12-13 Thread Misa Simic
Hi All, I am not sure how to define with words what I want to accomplish (so can't ask google the right question :) ) So will try to explain with sample data and expected result: Scenario 1) id thing_id category period_id 1 1 A 1 2 1 A 2 3 1 A 3 4 1 A 4 5 1 A 5 6 1 A 6 7 1 A 7 8 1 A 8