For us to be able to effectively help you, you need to provide two more pieces of information:
1. What are you trying to accomplish? It looks to me like you want to show the rank of a student based on their student id. What determines the rank? The best "averages" value?
2. In what way are the "select query results are wrong"?
Please follow-up to let us know how you made out. For good karma, mark a reply as the answer if it helped!