This is an extension of the typical "max value per group" solved like so: https://stackoverflow.com/a/12102216/510144
What I need is 1 step further - getting the row with the max values across multiple columns in a cascading fashion.
Given:
id | effective_time | revision | score
1 | 0 | 0 | 5
1 | 1 | 0 | 10
1 | 1 | 1 | 15
1 | 2 | 0 | 20
I need:
1 | 1 | 1 | 15
In plain english: what's the value for item with id
1 where the max effective_time
is less than 2 for the greatest revision
for that effectime_time