Re: Help needed with Window function - Mailing list pgsql-sql

From gmb
Subject Re: Help needed with Window function
Date
Msg-id 1380777056063-5773196.post@n5.nabble.com
Whole thread Raw
In response to Re: Help needed with Window function  (David Johnston <polobo@yahoo.com>)
Responses Re: Help needed with Window function  (Akihiro Okuno <choplin.choplin@gmail.com>)
List pgsql-sql
David Johnston wrote
> Basic idea: use ORDER BY in the window to auto-define a range-preceding
> frame.  Create an array of all dates (tags in the example) that match with
> positive amounts.  Negative amounts get their matching tag added to the
> array as NULL.  The provided function looks into the generated array and
> returns the last (closest to the current row in the frame) non-null
> date/tag in the array which ends up being the date/tag matching the last
> positive amount in the frame.
> 
> David J.

Hi David,

Thanks for your reply.
This is an approach I also considered, but hoped for a solution without the
expense (albeit small) of having to create a function. 
Just wanted to confirm that I'm not missing a simpler solution (my knowledge
in terms of window functions is rather limited).
Until something better comes along, I'll implement the solution as suggested
here.

Regards

GMB



--
View this message in context:
http://postgresql.1045698.n5.nabble.com/Help-needed-with-Window-function-tp5773160p5773196.html
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.



pgsql-sql by date:

Previous
From: David Johnston
Date:
Subject: Re: Help needed with Window function
Next
From: Akihiro Okuno
Date:
Subject: Re: Help needed with Window function