Question

Here is the problem. I have four columns that I want to present in a select query. But, I want the RSV column to have a 10-1 scale instead of its + and - values. The greatest number +8,6 should get 10. Several of the values in the bottom can have 1. I have absolutley no idea how to solve this...

Nr is race horses start number. A race can also contain less than fifteen horses

    Nr  RPO    RSP     RSV
1 10 9 +5,3 2 9 10 +8,6 3 8 7 -2,7 4 7 8 +3,8 5 6 4 +4,3 6 5 6 -1,0 7 4 5 +3,3 8 3 1 +6,6 9 2 1 +2,1 10 1 1 +3,8 11 1 3 +2,9 12 1 2 -2,1 13 1 1 +1,0 14 1 1 -1,0 15 1 1 +2,4

Last column shows the output:

               
Nr  RPO RSP RSV      RSVOutput
2   9   10  8,6      10
8   3   1   6,6      9
1   10  9   5,3      8
5   6   4   4,3      7
4   7   8   3,8      6
10  1   1   3,8      5
7   4   5   3,3      4
11  1   3   2,9      3
15  1   1   2,4      2
9   2   1   2,1      1
13  1   1   1        1
6   5   6   -1       1
14  1   1   -1       1
12  1   2   -2,1     1
3   8   7   -2,7     1
SELECT *
FROM rank
ORDER BY Nr
Was it helpful?

Solution

You could use something like this:

SELECT
  Nr, RPO, RSP, RSV,
  CASE WHEN @row>1 THEN @row:=@row-1 ELSE 1 END RSVOutput
FROM
  yourtable, (SELECT @row:=11) rows
ORDER BY
  RSV DESC

Please see fiddle here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top