L
L
lexstile2020-04-26 12:40:15
MySQL
lexstile, 2020-04-26 12:40:15

How to find out the position of a user in a table by a certain field and sorting?

There is a table with users.
The table has a field of type int - balance.
Is it possible to immediately return the position in the balance field with the direction desc?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2020-04-26
@lexstile

SELECT COUNT(*) + 1 AS `position`
  FROM `users`
  WHERE `balance` > (
    SELECT `balance`
      FROM `users`
      WHERE id = :userId
  )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question