0

我正在尝试从特定球队的球员最近的 20 个得分中提取信息。我查看球队名单,并提取这些球员参加过的所有比赛的相关信息。我想要每个球员最近的 20 场比赛。我在使用 LIMITs 和 GROUPs 时遇到了困难。我在这里阅读了关于使用用户定义的变量创建排名列,然后查询相关排名的答案,但我无法让排名部分起作用。

它目前将每一行都列为 1。

逻辑应该是,对于玩家来说,它会将最近的日期排为 1,然后随着行结果及时倒退而向上计数。新玩家的排名应重置为 1,然后根据需要再次计数。然后我会查询结果并限制在 <21 的排名。

任何帮助是极大的赞赏!

SET @currcount = NULL, @currvalue = NULL;

SELECT 
league_roster.player_name,

player_boxes.date, player_boxes.minutes, player_boxes.FG, 
player_boxes.FGA, player_boxes.3P, player_boxes.3PA, player_boxes.ft, player_boxes.fta, player_boxes.orb,
player_boxes.drb, player_boxes.tov, 

matchup_teamtotals.game_minutes, matchup_teamtotals.team_possessions,
matchup_teamtotals.opponent_possessions, matchup_teamtotals.possible_DRB, matchup_teamtotals.possible_ORB,
league_roster.team,

@currcount := IF(@currvalue = player_name, @currcount+1, 1) AS rank,
@currvalue := player_name AS whatever

FROM league_roster
INNER JOIN player_boxes ON player_boxes.player = player_name
INNER JOIN matchup_teamtotals ON matchup_teamtotals.matchup_id = player_boxes.matchup_id

WHERE league_roster.team = "Philadelphia 76ers"
ORDER BY player_name, date DESC




current output:
player:               date:           other fields              rank:
Tim Blackburn        Dec 31 2015       blah blah blah        1
Tim Blackburn        Dec 28 2015       blah blah blah        1
Tim Blackburn        Dec 27 2015       blah blah blah        1
Randy Johnson        Dec 31 2015       blah blah blah        1
Randy Johnson        Dec 27 2015       blah blah blah        1

desired output:
player:               date:           other fields              rank:
Tim Blackburn        Dec 31 2015       blah blah blah        1
Tim Blackburn        Dec 28 2015       blah blah blah        2
Tim Blackburn        Dec 27 2015       blah blah blah        3
Randy Johnson        Dec 31 2015       blah blah blah        1
Randy Johnson        Dec 27 2015       blah blah blah        2
4

0 回答 0