Skip to content
Advertisement

Calculate rank of the users based on their max score using mysql

I have a table (called users) I need rank of users based on their score but I want rank on the bases of users max score.

Expect result

Advertisement

Answer

You are looking for DENSE_RANK, But it supports mysql version higher than 8.0

  1. use correlated-subquery to get max value by each User_id
  2. use two variables one to store rank another to store previous value to make the DENSE_RANK number.

look like this.

Query 1:

Results:

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement