3

I need to count the position of the results in a Select - like a RANKING.

I have this:

"SELECT PLAYERID, SUM(POINTS) AS POINTS FROM TABLE1 GROUP BY PLAYERID ORDER BY POINTS"

And I Get this:

PLAYERID   POINTS
4          200
2          150
1          100
3           80

I need to know the position in the Ranking for PlayerID = 1.

I'm not an expert in MySQL - but it's possible to count the results like this:

RK   PLAYERID   POINTS
1     4         200
2     2         150
3     1         100
4     3          80

Something like: "SELECT COUNT..."

tks a lot! Daniel

EDIT: It's not duplicated because I don't want to create a ranking. I want to count the position of the result. The answer proposed here fits 100%.

DANIEL
  • 515
  • 7
  • 20

1 Answers1

2

You could try counting the numers of rows with points >= at the points of playerid = 1

select count(*)  from (
  SELECT PLAYERID
      , SUM(POINTS) AS POINTS 
  FROM TABLE1 
  GROUP BY PLAYERID 
) T 
WHERE T.POINT >= (
  SELECT SUM(POINTS) 
  FROM TABLE1 
  WHERE PLAYERID = 1
)
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107