"Gan Uesli Starling" <alias@starling.us> writes:
> I am trying to figure out how to winnow out in a single query (no
> intermediate
> tables) the most recent event for each sensor which has been 'Calibrated' or
> 'Repaired' not 'Damaged' afterwards.
I think you can probably do this with SELECT DISTINCT ON (look at the
"weather reports" example in the SELECT reference page). DISTINCT ON
is nonstandard, but the bog-standard ways to do this involve messy,
inefficient sub-SELECT constructions.
regards, tom lane