My query is taking too long to finish for finding the pair of rows where the difference of columns value is maximum group by another column

后端 未结 4 1250
醉话见心
醉话见心 2021-01-26 19:10

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

4条回答
  •  太阳男子
    2021-01-26 19:49

    select distinct(session) * from (
    select  t1.session, t1.center, t2.center, 
    (case when t1.performance > t2.performance then (t1.performance-t2.performance) else (t2.performance-t1.performance))as performance_diff 
    from mytable t1, mytable t2 
    where t1.session=t2.session and t1.center!=t2.center) as T1 order by session,performance_diff desc limit 1;
    

提交回复
热议问题