Gunther Schadow <gunther(at)aurora(dot)regenstrief(dot)org> writes:
> A very frequent decision support query we have to make is to get the
> last act of a certain type that occurred before a certain cut-off
> date.
This seems pretty close to the type of problem DISTINCT ON is intended
to solve. Look at the "weather report" example in the SELECT reference
page.
regards, tom lane