vendredi 14 août 2015

return column name with closest value

So I don't know if this is possible, but I would like to return the name of the column which has the closet value to my query.

So this is my table:

--------------------------
| ID | D1 | D2 | D3 | D4 |
--------------------------
| 1  | 0  | 10 | 22 | 50 |
--------------------------

I would like to do a query where I am searching in D1 to D4 for the closest value of 20, in this case D3

Then I would like to return D3 and the value in it.

So my answer should be:

------
| D3 |
------
| 22 |
------

Is this by any way possible?

Aucun commentaire:

Enregistrer un commentaire