Say, I\'ve a table like this:
I want to find the pair of Centers whose Performance difference is highest for each session, like this:
I have th
Grouping by session and taking the group's min and max performance seems logical. The actual centers unfortunately need a subquery/join here.
select g.session as Session,
(select min(center) from mytable
where session = g.session and performance = g.maxim) as Center1,
(select min(center) from mytable
where session = g.session and performance = g.minim) as Center2,
g.maxim - g.minim as Performance
from (select
t1.session,
min(t1.performance) as minim,
max(t1.performance) as maxim
from mytable t1
group by t1.session)
as g
Ensure an index on session and performance.