Answer the question
In order to leave comments, you need to log in
How to get row number + sorted by one column?
I am writing a telegram bot like a quiz. I have a PostgreSQL table which has id (SERIAL), user_id of the telegram user, the number of answers in total, correct and incorrect. I need to show the user his place in the general list by the number of correct answers. But I don't know how to implement it. I tried making a request like this:
SELECT user_id, row_number() OVER(ORDER BY right DESC) as number FROM users
SELECT user_id, row_number() OVER(ORDER BY right DESC) as number FROM users WHERE user_id=%s
Answer the question
In order to leave comments, you need to log in
Simplified:
select * from (select ..... ) as abc where abc.user=xxx
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question