1

I need help finding the total points of a player and Team name based on this table:

Tbl.STATS [Match_ID,Player_ID,Points_Scored,Team_Name]

Any advice or help would be much appreciated!

4
  • Can a player play for multiple teams (transfers)? What do you mean "MAX total"? MAX and SUM are two different things. Also what RDBMS are you using? Commented Mar 20, 2011 at 23:07
  • A player can play for multiple teams via a TRANSFERS entity, but it's not needed in this instance. This would be for the current stats post transfer season. I'm using ORACLE 2007. Commented Mar 20, 2011 at 23:19
  • So are you looking for the single player/team combination that has scored the most points in total or something different to that? Commented Mar 20, 2011 at 23:22
  • I'm looking to find the player that scored the most total points and what team the player is on. Commented Mar 20, 2011 at 23:35

3 Answers 3

2

All players on all teams

select player_id, team_name, sum(points_scored) sum_score
from stats
group by player_id, team_name
order by sum_score desc

A player and team name (for example, Bob playing for Eagles, so not considering when Bob played for Sharks)

select sum(points_scored) sum_score
from stats
where player_id = 1 and team_name = 'Eagles'

But the question asks something else again, so going by the question, the MAX total score:

select max(sum_score) MaxTotalScore
from
(
    select player_id, team_name, sum(points_scored) sum_score
    from stats
    group by player_id, team_name
) X
Sign up to request clarification or add additional context in comments.

Comments

0

SELECT player_id, team_name, sum(points_scored) FROM STATS Group by player_id, team_name

Comments

0

"I'm looking to find the player that scored the most total points and what team the player is on."

I don't normally dabble in the Oracle tag but I believe this should work!

WITH T AS
(
SELECT Player_ID, 
       Team_Name, 
       SUM(Points_Scored) OVER (PARTITION BY Player_ID) AS Points_Total
FROM Tbl.STATS 
), T2 AS
(
SELECT Player_ID, 
       Team_Name, 
       Points_Total,
       RANK() OVER (ORDER BY Points_Total DESC) AS RN
FROM T       
)
SELECT Player_ID, 
       Team_Name, 
       Points_Total
FROM T2 
WHERE RN=1

1 Comment

Thanks! I also have SQL Server, and I'm trying to figure it out there as well. Sorry for being a pain.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.