O
O
ojiekcahdp2021-08-29 18:55:53
MySQL
ojiekcahdp, 2021-08-29 18:55:53

How to get the position of a record in a table relative to MySQL sort?

There is a table with data: NAME, RATING.
I need to get the position of this NAME, relative to sorting, who has a higher rating.
I would be grateful for help!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2021-08-29
@ojiekcahdp

SELECT COUNT(*) + 1 AS `position`
  FROM `table` 
  WHERE `RATING` > (
    SELECT `RATING`
      FROM `table`
      WHERE `NAME` = :name
      LIMIT 1
  )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question