Jump to content

Get the ranking of a certain column in one query


ninedoors

Recommended Posts

I am trying to find the rank for a player in my hockey league in goals.  I have the goals stored so that each row is a goal with a user id in it as well as a team id.

 

What I would like to do is be able to put in userid = 3 and get that users rank in the league in goals.  I came across a solution in google but don't understand it completely as I haven't been using mySQL that long and don't understand how to use dervived tables from a query.

 

Here is the code they used to get a score from a game which is similar to my problem:

 

        'SET @rownum := 0;

        SELECT id_member, rank 
        FROM (
        SELECT @rownum := @rownum+1 AS rank, id_member, team_id, SUM(IF(action_id = 1, 1, 0)) as goals FROM smf_osm_scoring
       GROUP BY id_member 
       ORDER BY goals DESC
        ) AS derived_table WHERE id_member = 1;'

 

Any help or direction would be great, even if it is read this book, as I would love to be able to understand this concept rather than just have it done for me.

 

Nick

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.