0

I have a bit of a problem. I need to sort multiple columns after there value, but also rearrange the rows depending which has the highest value. It's a bit easier if I give you an example.

My table:

name team erg1 erg2 erg3 erg4 erg5

Mike   Blue 56    70     23     7      0

Dave   Red 20    35     89   23    31

Peter Green 5     90     23    0      0

the result I need is something like this:

name team erg1 erg2 erg3 erg4 erg5

Peter Green 90     23      5       0      0

Dave   Red   89     35    31     23    20

Mike   Blue    70    56     23       7     0

it doesen't really matter in witch column the value was before sorting. Does somebody understand what I need or kown how I can do that?

1
  • This is painful to do in SQLite. Commented Sep 7, 2016 at 23:20

2 Answers 2

1

You need to upate values in the rows. The below is really long and repetitive, but it should work.

 Update myTable set
     erg1 = case when erg1 > erg2 and erg1 > erg3 and erg1 > erg4 
                             and erg1 > erg5 then erg1
                 when erg2 > erg1 and erg2 > erg3 and erg2 > erg4 
                             and erg1 > ergthen erg2 
                 when erg3 > erg1 and erg3 > erg2 and erg3 > erg4 
                             and erg3 > erg5 then erg3
                 when erg4 > erg1 and erg4 > erg2 and erg4 > erg3 
                             and erg4 > erg5 then erg4 else erg5 end,
     erg2 = case when erg1 < erg2 and erg1 > erg3 and erg1 > erg4 
                             and erg1 > erg5  then erg1
                 when erg2 < erg1 and erg2 > erg3 and erg2 > erg4 
                             and erg1 > erg5  then erg2
                 when erg3 < erg1 and erg3 > erg2 and erg3 > erg4 
                             and erg3 > erg5 then erg3
                 when erg4 < erg1 and erg4 > erg2 and erg4 > erg3 
                             and erg4 > erg5 then erg4 else erg5 end,
     erg3 = case when erg1 < erg2 and erg1 < erg3 and erg1 > erg4 
                             and erg1 > erg5 then erg1
                 when erg2 < erg1 and erg2 < erg3 and erg2 > erg4 
                             and erg1 > erg5 then erg2
                 when erg3 < erg1 and erg3 < erg2 and erg3 > erg4 
                             and erg3 > erg5 then erg3
                 when erg4 < erg1 and erg4 < erg2 and erg4 > erg3 
                             and erg4 > erg5 then erg4  else erg5 end,
     erg4 = case when erg1 < erg2 and erg1 < erg3 and erg1 < erg4 
                             and erg1 > erg5  then erg1
                 when erg2 < erg1 and erg2 < erg3 and erg2 < erg4 
                             and erg1 > erg5 then erg2
                 when erg3 < erg1 and erg3 < erg2 and erg3 < erg4 
                             and erg3 > erg5 then erg3
                 when erg4 < erg1 and erg4 < erg2 and erg4 < erg3 
                             and erg4 > erg5 then erg4 else erg5 end,
     erg5 = case when erg1 < erg2 and erg1 < erg3 and erg1 < erg4 
                             and erg1 < erg5  then erg1
                 when erg2 < erg1 and erg2 < erg3 and erg2 < erg4 
                             and erg1 < erg5 then erg2
                 when erg3 < erg1 and erg3 < erg2 and erg3 < erg4 
                             and erg3 < erg5 then erg3
                 when erg4 < erg1 and erg4 < erg2 and erg4 < erg3 
                             and erg4 < erg5 then erg4  else erg5 end
Sign up to request clarification or add additional context in comments.

2 Comments

Thank for the answer. This is going to be a pain in the butt, because i actually have not only 5 but 10 columns that i need to sort.
You need to re-evaluate what and why you are doing this.
0

so i added the other half of the columns and now it doesn't work properly. Now it sets every column to the highest value. Here is the edited code:

UPDATE temp SET
 erg1 = case when erg1 > erg2 and erg1 > erg3 and erg1 > erg4 
                         and erg1 > erg5 and erg1 > erg6 and erg1 > erg7
                         and erg1 > erg8 and erg1 > erg9 and erg1 > erg10 
                         then erg1
             when erg2 > erg1 and erg2 > erg3 and erg2 > erg4 
                         and erg2 > erg5 and erg2 > erg6 and erg2 > erg7  
                         and erg2 > erg8 and erg2 > erg9 and erg2 >erg10
                         then erg2 
             when erg3 > erg1 and erg3 > erg2 and erg3 > erg4 
                         and erg3 > erg5 and erg3 > erg6 and erg3 > erg7 
                         and erg3 > erg8 and erg3 > erg9 and erg3 >erg10
                         then erg3
             when erg4 > erg1 and erg4 > erg2 and erg4 > erg3 
                         and erg4 > erg5 and erg4 > erg6 and erg4 > erg7
                         and erg4 > erg8 and erg4 > erg9 and erg4 >erg10
                         then erg4 
             when erg5 > erg1 and erg5 > erg2 and erg5 > erg3 
                         and erg5 > erg4 and erg5 > erg6 and erg5 > erg7
                         and erg5 > erg8 and erg3 > erg9 and erg3 >erg10
                         then erg5
             when erg6 > erg1 and erg6 > erg2 and erg6 > erg3 
                         and erg6 > erg4 and erg6 > erg5 and erg6 > erg7
                         and erg6 > erg8 and erg6 > erg9 and erg6 >erg10
                         then erg6
             when erg7 > erg1 and erg7 > erg2 and erg7 > erg3 
                         and erg7 > erg4 and erg7 > erg5 and erg7 > erg6
                         and erg7 > erg8 and erg7 > erg9 and erg7 >erg10
                         then erg7
             when erg8 > erg1 and erg8 > erg2 and erg8 > erg3 
                         and erg8 > erg4 and erg8 > erg5 and erg8 > erg6
                         and erg8 > erg7 and erg8 > erg9 and erg8 >erg10
                         then erg8
             when erg9 > erg1 and erg9 > erg2 and erg9 > erg3 
                         and erg9 > erg4 and erg9 > erg5 and erg9 > erg6
                         and erg9 > erg7 and erg9 > erg8 and erg9 >erg10
                         then erg9 else erg10 end,                       
 erg2 = case when erg1 > erg2 and erg1 > erg3 and erg1 > erg4 
                         and erg1 > erg5 and erg1 > erg6 and erg1 > erg7
                         and erg1 > erg8 and erg1 > erg9 and erg1 > erg10 
                         then erg1
             when erg2 > erg1 and erg2 > erg3 and erg2 > erg4 
                         and erg2 > erg5 and erg2 > erg6 and erg2 > erg7  
                         and erg2 > erg8 and erg2 > erg9 and erg2 >erg10
                         then erg2 
             when erg3 > erg1 and erg3 > erg2 and erg3 > erg4 
                         and erg3 > erg5 and erg3 > erg6 and erg3 > erg7 
                         and erg3 > erg8 and erg3 > erg9 and erg3 >erg10
                         then erg3
             when erg4 > erg1 and erg4 > erg2 and erg4 > erg3 
                         and erg4 > erg5 and erg4 > erg6 and erg4 > erg7
                         and erg4 > erg8 and erg4 > erg9 and erg4 >erg10
                         then erg4 
             when erg5 > erg1 and erg5 > erg2 and erg5 > erg3 
                         and erg5 > erg4 and erg5 > erg6 and erg5 > erg7
                         and erg5 > erg8 and erg3 > erg9 and erg3 >erg10
                         then erg5
             when erg6 > erg1 and erg6 > erg2 and erg6 > erg3 
                         and erg6 > erg4 and erg6 > erg5 and erg6 > erg7
                         and erg6 > erg8 and erg6 > erg9 and erg6 >erg10
                         then erg6
             when erg7 > erg1 and erg7 > erg2 and erg7 > erg3 
                         and erg7 > erg4 and erg7 > erg5 and erg7 > erg6
                         and erg7 > erg8 and erg7 > erg9 and erg7 >erg10
                         then erg7
             when erg8 > erg1 and erg8 > erg2 and erg8 > erg3 
                         and erg8 > erg4 and erg8 > erg5 and erg8 > erg6
                         and erg8 > erg7 and erg8 > erg9 and erg8 >erg10
                         then erg8
             when erg9 > erg1 and erg9 > erg2 and erg9 > erg3 
                         and erg9 > erg4 and erg9 > erg5 and erg9 > erg6
                         and erg9 > erg7 and erg9 > erg8 and erg9 >erg10
                         then erg9 else erg10 end,  
 erg3 = case when erg1 > erg2 and erg1 > erg3 and erg1 > erg4 
                         and erg1 > erg5 and erg1 > erg6 and erg1 > erg7
                         and erg1 > erg8 and erg1 > erg9 and erg1 > erg10 
                         then erg1
             when erg2 > erg1 and erg2 > erg3 and erg2 > erg4 
                         and erg2 > erg5 and erg2 > erg6 and erg2 > erg7  
                         and erg2 > erg8 and erg2 > erg9 and erg2 >erg10
                         then erg2 
             when erg3 > erg1 and erg3 > erg2 and erg3 > erg4 
                         and erg3 > erg5 and erg3 > erg6 and erg3 > erg7 
                         and erg3 > erg8 and erg3 > erg9 and erg3 >erg10
                         then erg3
             when erg4 > erg1 and erg4 > erg2 and erg4 > erg3 
                         and erg4 > erg5 and erg4 > erg6 and erg4 > erg7
                         and erg4 > erg8 and erg4 > erg9 and erg4 >erg10
                         then erg4 
             when erg5 > erg1 and erg5 > erg2 and erg5 > erg3 
                         and erg5 > erg4 and erg5 > erg6 and erg5 > erg7
                         and erg5 > erg8 and erg3 > erg9 and erg3 >erg10
                         then erg5
             when erg6 > erg1 and erg6 > erg2 and erg6 > erg3 
                         and erg6 > erg4 and erg6 > erg5 and erg6 > erg7
                         and erg6 > erg8 and erg6 > erg9 and erg6 >erg10
                         then erg6
             when erg7 > erg1 and erg7 > erg2 and erg7 > erg3 
                         and erg7 > erg4 and erg7 > erg5 and erg7 > erg6
                         and erg7 > erg8 and erg7 > erg9 and erg7 >erg10
                         then erg7
             when erg8 > erg1 and erg8 > erg2 and erg8 > erg3 
                         and erg8 > erg4 and erg8 > erg5 and erg8 > erg6
                         and erg8 > erg7 and erg8 > erg9 and erg8 >erg10
                         then erg8
             when erg9 > erg1 and erg9 > erg2 and erg9 > erg3 
                         and erg9 > erg4 and erg9 > erg5 and erg9 > erg6
                         and erg9 > erg7 and erg9 > erg8 and erg9 >erg10
                         then erg9 else erg10 end,  
 erg4 = case when erg1 > erg2 and erg1 > erg3 and erg1 > erg4 
                         and erg1 > erg5 and erg1 > erg6 and erg1 > erg7
                         and erg1 > erg8 and erg1 > erg9 and erg1 > erg10 
                         then erg1
             when erg2 > erg1 and erg2 > erg3 and erg2 > erg4 
                         and erg2 > erg5 and erg2 > erg6 and erg2 > erg7  
                         and erg2 > erg8 and erg2 > erg9 and erg2 >erg10
                         then erg2 
             when erg3 > erg1 and erg3 > erg2 and erg3 > erg4 
                         and erg3 > erg5 and erg3 > erg6 and erg3 > erg7 
                         and erg3 > erg8 and erg3 > erg9 and erg3 >erg10
                         then erg3
             when erg4 > erg1 and erg4 > erg2 and erg4 > erg3 
                         and erg4 > erg5 and erg4 > erg6 and erg4 > erg7
                         and erg4 > erg8 and erg4 > erg9 and erg4 >erg10
                         then erg4 
             when erg5 > erg1 and erg5 > erg2 and erg5 > erg3 
                         and erg5 > erg4 and erg5 > erg6 and erg5 > erg7
                         and erg5 > erg8 and erg3 > erg9 and erg3 >erg10
                         then erg5
             when erg6 > erg1 and erg6 > erg2 and erg6 > erg3 
                         and erg6 > erg4 and erg6 > erg5 and erg6 > erg7
                         and erg6 > erg8 and erg6 > erg9 and erg6 >erg10
                         then erg6
             when erg7 > erg1 and erg7 > erg2 and erg7 > erg3 
                         and erg7 > erg4 and erg7 > erg5 and erg7 > erg6
                         and erg7 > erg8 and erg7 > erg9 and erg7 >erg10
                         then erg7
             when erg8 > erg1 and erg8 > erg2 and erg8 > erg3 
                         and erg8 > erg4 and erg8 > erg5 and erg8 > erg6
                         and erg8 > erg7 and erg8 > erg9 and erg8 >erg10
                         then erg8
             when erg9 > erg1 and erg9 > erg2 and erg9 > erg3 
                         and erg9 > erg4 and erg9 > erg5 and erg9 > erg6
                         and erg9 > erg7 and erg9 > erg8 and erg9 >erg10
                         then erg9 else erg10 end,  
 erg5 = case when erg1 > erg2 and erg1 > erg3 and erg1 > erg4 
                         and erg1 > erg5 and erg1 > erg6 and erg1 > erg7
                         and erg1 > erg8 and erg1 > erg9 and erg1 > erg10 
                         then erg1
             when erg2 > erg1 and erg2 > erg3 and erg2 > erg4 
                         and erg2 > erg5 and erg2 > erg6 and erg2 > erg7  
                         and erg2 > erg8 and erg2 > erg9 and erg2 >erg10
                         then erg2 
             when erg3 > erg1 and erg3 > erg2 and erg3 > erg4 
                         and erg3 > erg5 and erg3 > erg6 and erg3 > erg7 
                         and erg3 > erg8 and erg3 > erg9 and erg3 >erg10
                         then erg3
             when erg4 > erg1 and erg4 > erg2 and erg4 > erg3 
                         and erg4 > erg5 and erg4 > erg6 and erg4 > erg7
                         and erg4 > erg8 and erg4 > erg9 and erg4 >erg10
                         then erg4 
             when erg5 > erg1 and erg5 > erg2 and erg5 > erg3 
                         and erg5 > erg4 and erg5 > erg6 and erg5 > erg7
                         and erg5 > erg8 and erg3 > erg9 and erg3 >erg10
                         then erg5
             when erg6 > erg1 and erg6 > erg2 and erg6 > erg3 
                         and erg6 > erg4 and erg6 > erg5 and erg6 > erg7
                         and erg6 > erg8 and erg6 > erg9 and erg6 >erg10
                         then erg6
             when erg7 > erg1 and erg7 > erg2 and erg7 > erg3 
                         and erg7 > erg4 and erg7 > erg5 and erg7 > erg6
                         and erg7 > erg8 and erg7 > erg9 and erg7 >erg10
                         then erg7
             when erg8 > erg1 and erg8 > erg2 and erg8 > erg3 
                         and erg8 > erg4 and erg8 > erg5 and erg8 > erg6
                         and erg8 > erg7 and erg8 > erg9 and erg8 >erg10
                         then erg8
             when erg9 > erg1 and erg9 > erg2 and erg9 > erg3 
                         and erg9 > erg4 and erg9 > erg5 and erg9 > erg6
                         and erg9 > erg7 and erg9 > erg8 and erg9 >erg10
                         then erg9 else erg10 end,
 erg6 = case when erg1 > erg2 and erg1 > erg3 and erg1 > erg4 
                         and erg1 > erg5 and erg1 > erg6 and erg1 > erg7
                         and erg1 > erg8 and erg1 > erg9 and erg1 > erg10 
                         then erg1
             when erg2 > erg1 and erg2 > erg3 and erg2 > erg4 
                         and erg2 > erg5 and erg2 > erg6 and erg2 > erg7  
                         and erg2 > erg8 and erg2 > erg9 and erg2 >erg10
                         then erg2 
             when erg3 > erg1 and erg3 > erg2 and erg3 > erg4 
                         and erg3 > erg5 and erg3 > erg6 and erg3 > erg7 
                         and erg3 > erg8 and erg3 > erg9 and erg3 >erg10
                         then erg3
             when erg4 > erg1 and erg4 > erg2 and erg4 > erg3 
                         and erg4 > erg5 and erg4 > erg6 and erg4 > erg7
                         and erg4 > erg8 and erg4 > erg9 and erg4 >erg10
                         then erg4 
             when erg5 > erg1 and erg5 > erg2 and erg5 > erg3 
                         and erg5 > erg4 and erg5 > erg6 and erg5 > erg7
                         and erg5 > erg8 and erg3 > erg9 and erg3 >erg10
                         then erg5
             when erg6 > erg1 and erg6 > erg2 and erg6 > erg3 
                         and erg6 > erg4 and erg6 > erg5 and erg6 > erg7
                         and erg6 > erg8 and erg6 > erg9 and erg6 >erg10
                         then erg6
             when erg7 > erg1 and erg7 > erg2 and erg7 > erg3 
                         and erg7 > erg4 and erg7 > erg5 and erg7 > erg6
                         and erg7 > erg8 and erg7 > erg9 and erg7 >erg10
                         then erg7
             when erg8 > erg1 and erg8 > erg2 and erg8 > erg3 
                         and erg8 > erg4 and erg8 > erg5 and erg8 > erg6
                         and erg8 > erg7 and erg8 > erg9 and erg8 >erg10
                         then erg8
             when erg9 > erg1 and erg9 > erg2 and erg9 > erg3 
                         and erg9 > erg4 and erg9 > erg5 and erg9 > erg6
                         and erg9 > erg7 and erg9 > erg8 and erg9 >erg10
                         then erg9 else erg10 end,
  erg7 = case when erg1 > erg2 and erg1 > erg3 and erg1 > erg4 
                         and erg1 > erg5 and erg1 > erg6 and erg1 > erg7
                         and erg1 > erg8 and erg1 > erg9 and erg1 > erg10 
                         then erg1
             when erg2 > erg1 and erg2 > erg3 and erg2 > erg4 
                         and erg2 > erg5 and erg2 > erg6 and erg2 > erg7  
                         and erg2 > erg8 and erg2 > erg9 and erg2 >erg10
                         then erg2 
             when erg3 > erg1 and erg3 > erg2 and erg3 > erg4 
                         and erg3 > erg5 and erg3 > erg6 and erg3 > erg7 
                         and erg3 > erg8 and erg3 > erg9 and erg3 >erg10
                         then erg3
             when erg4 > erg1 and erg4 > erg2 and erg4 > erg3 
                         and erg4 > erg5 and erg4 > erg6 and erg4 > erg7
                         and erg4 > erg8 and erg4 > erg9 and erg4 >erg10
                         then erg4 
             when erg5 > erg1 and erg5 > erg2 and erg5 > erg3 
                         and erg5 > erg4 and erg5 > erg6 and erg5 > erg7
                         and erg5 > erg8 and erg3 > erg9 and erg3 >erg10
                         then erg5
             when erg6 > erg1 and erg6 > erg2 and erg6 > erg3 
                         and erg6 > erg4 and erg6 > erg5 and erg6 > erg7
                         and erg6 > erg8 and erg6 > erg9 and erg6 >erg10
                         then erg6
             when erg7 > erg1 and erg7 > erg2 and erg7 > erg3 
                         and erg7 > erg4 and erg7 > erg5 and erg7 > erg6
                         and erg7 > erg8 and erg7 > erg9 and erg7 >erg10
                         then erg7
             when erg8 > erg1 and erg8 > erg2 and erg8 > erg3 
                         and erg8 > erg4 and erg8 > erg5 and erg8 > erg6
                         and erg8 > erg7 and erg8 > erg9 and erg8 >erg10
                         then erg8
             when erg9 > erg1 and erg9 > erg2 and erg9 > erg3 
                         and erg9 > erg4 and erg9 > erg5 and erg9 > erg6
                         and erg9 > erg7 and erg9 > erg8 and erg9 >erg10
                         then erg9 else erg10 end,                           
 erg8 = case when erg1 > erg2 and erg1 > erg3 and erg1 > erg4 
                         and erg1 > erg5 and erg1 > erg6 and erg1 > erg7
                         and erg1 > erg8 and erg1 > erg9 and erg1 > erg10 
                         then erg1
             when erg2 > erg1 and erg2 > erg3 and erg2 > erg4 
                         and erg2 > erg5 and erg2 > erg6 and erg2 > erg7  
                         and erg2 > erg8 and erg2 > erg9 and erg2 >erg10
                         then erg2 
             when erg3 > erg1 and erg3 > erg2 and erg3 > erg4 
                         and erg3 > erg5 and erg3 > erg6 and erg3 > erg7 
                         and erg3 > erg8 and erg3 > erg9 and erg3 >erg10
                         then erg3
             when erg4 > erg1 and erg4 > erg2 and erg4 > erg3 
                         and erg4 > erg5 and erg4 > erg6 and erg4 > erg7
                         and erg4 > erg8 and erg4 > erg9 and erg4 >erg10
                         then erg4 
             when erg5 > erg1 and erg5 > erg2 and erg5 > erg3 
                         and erg5 > erg4 and erg5 > erg6 and erg5 > erg7
                         and erg5 > erg8 and erg3 > erg9 and erg3 >erg10
                         then erg5
             when erg6 > erg1 and erg6 > erg2 and erg6 > erg3 
                         and erg6 > erg4 and erg6 > erg5 and erg6 > erg7
                         and erg6 > erg8 and erg6 > erg9 and erg6 >erg10
                         then erg6
             when erg7 > erg1 and erg7 > erg2 and erg7 > erg3 
                         and erg7 > erg4 and erg7 > erg5 and erg7 > erg6
                         and erg7 > erg8 and erg7 > erg9 and erg7 >erg10
                         then erg7
             when erg8 > erg1 and erg8 > erg2 and erg8 > erg3 
                         and erg8 > erg4 and erg8 > erg5 and erg8 > erg6
                         and erg8 > erg7 and erg8 > erg9 and erg8 >erg10
                         then erg8
             when erg9 > erg1 and erg9 > erg2 and erg9 > erg3 
                         and erg9 > erg4 and erg9 > erg5 and erg9 > erg6
                         and erg9 > erg7 and erg9 > erg8 and erg9 >erg10
                         then erg9 else erg10 end,
 erg9 = case when erg1 > erg2 and erg1 > erg3 and erg1 > erg4 
                         and erg1 > erg5 and erg1 > erg6 and erg1 > erg7
                         and erg1 > erg8 and erg1 > erg9 and erg1 > erg10 
                         then erg1
             when erg2 > erg1 and erg2 > erg3 and erg2 > erg4 
                         and erg2 > erg5 and erg2 > erg6 and erg2 > erg7  
                         and erg2 > erg8 and erg2 > erg9 and erg2 >erg10
                         then erg2 
             when erg3 > erg1 and erg3 > erg2 and erg3 > erg4 
                         and erg3 > erg5 and erg3 > erg6 and erg3 > erg7 
                         and erg3 > erg8 and erg3 > erg9 and erg3 >erg10
                         then erg3
             when erg4 > erg1 and erg4 > erg2 and erg4 > erg3 
                         and erg4 > erg5 and erg4 > erg6 and erg4 > erg7
                         and erg4 > erg8 and erg4 > erg9 and erg4 >erg10
                         then erg4 
             when erg5 > erg1 and erg5 > erg2 and erg5 > erg3 
                         and erg5 > erg4 and erg5 > erg6 and erg5 > erg7
                         and erg5 > erg8 and erg3 > erg9 and erg3 >erg10
                         then erg5
             when erg6 > erg1 and erg6 > erg2 and erg6 > erg3 
                         and erg6 > erg4 and erg6 > erg5 and erg6 > erg7
                         and erg6 > erg8 and erg6 > erg9 and erg6 >erg10
                         then erg6
             when erg7 > erg1 and erg7 > erg2 and erg7 > erg3 
                         and erg7 > erg4 and erg7 > erg5 and erg7 > erg6
                         and erg7 > erg8 and erg7 > erg9 and erg7 >erg10
                         then erg7
             when erg8 > erg1 and erg8 > erg2 and erg8 > erg3 
                         and erg8 > erg4 and erg8 > erg5 and erg8 > erg6
                         and erg8 > erg7 and erg8 > erg9 and erg8 >erg10
                         then erg8
             when erg9 > erg1 and erg9 > erg2 and erg9 > erg3 
                         and erg9 > erg4 and erg9 > erg5 and erg9 > erg6
                         and erg9 > erg7 and erg9 > erg8 and erg9 >erg10
                         then erg9 else erg10 end,
 erg10 = case when erg1 > erg2 and erg1 > erg3 and erg1 > erg4 
                         and erg1 > erg5 and erg1 > erg6 and erg1 > erg7
                         and erg1 > erg8 and erg1 > erg9 and erg1 > erg10 
                         then erg1
             when erg2 > erg1 and erg2 > erg3 and erg2 > erg4 
                         and erg2 > erg5 and erg2 > erg6 and erg2 > erg7  
                         and erg2 > erg8 and erg2 > erg9 and erg2 >erg10
                         then erg2 
             when erg3 > erg1 and erg3 > erg2 and erg3 > erg4 
                         and erg3 > erg5 and erg3 > erg6 and erg3 > erg7 
                         and erg3 > erg8 and erg3 > erg9 and erg3 >erg10
                         then erg3
             when erg4 > erg1 and erg4 > erg2 and erg4 > erg3 
                         and erg4 > erg5 and erg4 > erg6 and erg4 > erg7
                         and erg4 > erg8 and erg4 > erg9 and erg4 >erg10
                         then erg4 
             when erg5 > erg1 and erg5 > erg2 and erg5 > erg3 
                         and erg5 > erg4 and erg5 > erg6 and erg5 > erg7
                         and erg5 > erg8 and erg3 > erg9 and erg3 >erg10
                         then erg5
             when erg6 > erg1 and erg6 > erg2 and erg6 > erg3 
                         and erg6 > erg4 and erg6 > erg5 and erg6 > erg7
                         and erg6 > erg8 and erg6 > erg9 and erg6 >erg10
                         then erg6
             when erg7 > erg1 and erg7 > erg2 and erg7 > erg3 
                         and erg7 > erg4 and erg7 > erg5 and erg7 > erg6
                         and erg7 > erg8 and erg7 > erg9 and erg7 >erg10
                         then erg7
             when erg8 > erg1 and erg8 > erg2 and erg8 > erg3 
                         and erg8 > erg4 and erg8 > erg5 and erg8 > erg6
                         and erg8 > erg7 and erg8 > erg9 and erg8 >erg10
                         then erg8
             when erg9 > erg1 and erg9 > erg2 and erg9 > erg3 
                         and erg9 > erg4 and erg9 > erg5 and erg9 > erg6
                         and erg9 > erg7 and erg9 > erg8 and erg9 >erg10
                         then erg9 else erg10 end

2 Comments

You really need to reevaluate what you are doing and why you are doing it. This violates so many principals of database design it is frightening. If the values are not associated with the names of columns by something other than the relative value itself, then this is not the correct schema. The values should then just be stored in a separate two or three column child table related to the name/Team table. (name, team, erg) Sorting, if required should be done on the fly by query that fetches the rows.
And you failed to notice the pattern for the use of the comparison operators </>. The operator is a > for the comparisons with higher indexed columns than the one the expression is for, and < for the lower indexed ones. Look carefully at the </> operators in my answer again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.