V
V
Vlad Osadchyi2020-06-19 17:32:22
MySQL
Vlad Osadchyi, 2020-06-19 17:32:22

How to get the row number in the selection and the slice of the selection around this row?

There is a users table with id and points fields, points is of double type.
How, knowing the user id, to get the line number with this user in the selection sorted by points?
That is, it will be the user's place in the ranking.
And how to get 5 users before and 5 users after this user in the rating?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Armenian Radio, 2020-06-19
@gbg

select * from tbl order by user.rating - :target
union
select * from tbl order by :target - user.rating

Set your own limit.

D
d-stream, 2020-06-19
@d-stream

https://dev.mysql.com/doc/refman/8.0/en/window-fun...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question