Não é só usar a função rank()?

W.