ninedoors Posted March 17, 2010 Share Posted March 17, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/195590-get-the-ranking-of-a-certain-column-in-one-query/ Share on other sites More sharing options...
fenway Posted March 20, 2010 Share Posted March 20, 2010 See here. Quote Link to comment https://forums.phpfreaks.com/topic/195590-get-the-ranking-of-a-certain-column-in-one-query/#findComment-1029308 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.