I have a table with an id and a value.
How can I rank an element of the table in order desc by its value?
What I want to do is:
SELECT id FROM table ORDER BY value DESC
And i want it to tell me for exemple the position of id=4
thanks a lot for answering!
MySQL does not have analytic functions, so you have to use user variables:
To get the rank of a particular record, wrap it in an outer query:
To save MySQL from needlessly calculating the rank of every record in the table, you could add a filter: