How to know the current position of the user in the ranking

Asked

Viewed 62 times

4

I have the table quiz_general and the table account, the table quiz_general that’s how it is:

inserir a descrição da imagem aqui

I’m doing a ranking system, it uses several lines to make the sum of points of each user, not just one line (for various complexities that can’t be explained). The system has more than 3000 users. The site will show the position of the first 5 people, so:

SELECT conta.nome, conta.area, conta.departamento,
SUM(quiz_geral.ponto) AS pontosTotais
FROM quiz_geral
INNER JOIN conta ON quiz_geral.idconta = conta.id
GROUP BY quiz_geral.idconta
ORDER BY pontosTotais DESC
LIMIT 5

It works perfectly. And I also need to show the ranking position of the user who is logged in to the system (it can be the 4th or 775th, any position).

As there are more than 3000 users, it would be very bad to go through the entire table to know the position only of the logged-in user. How to get around this? Is there any way to make a select for it?

I created a SQL Fiddle to better understand: http://sqlfiddle.com/#! 9/b65f0/2 In the example I wanted to try to list the position of the user Camila, which is 2, without having to go through all the lines

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.