Jump to content

Recommended Posts

I am trying to get the rank of each team direct from a select statement.

 

My ultimate goal is to select the rank of a team depending on the number of total points, and also the number of total points minus the last 7 days in the same select statement as to get the change in rank.

 

I am currently doing this using a select query inside a while loop which is loading very slowly as there are currently about 100 rows and think if it were in one statement it would load much quicker.

 

But I can't even get the rank for the total points. I thought if I did this first then I could use a join to also select the rank of the total points minus the last 7 days.

 

I was thinking something like this would work:

 

SELECT t1.team_id, SUM(t1.points) AS total1, COUNT(t2.team_id) AS rank
FROM team_points t1
LEFT JOIN
   (SELECT team_id, SUM(points) AS total2 
   FROM team_points 
   GROUP BY team_id) AS t2
ON t1.total1 < t2.total2
GROUP BY team_id
ORDER BY total DESC

But that's not right. It gives the error Unknown column 't1.total1' in 'on clause'. I am struggling to get my head around this. I have tried many other ways without success. Does anybody have any ideas? Or am I better off sticking to my old way?

 

Link to comment
https://forums.phpfreaks.com/topic/276263-select-rank/
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.