MySQL Query to get top 3 players for each week

We run a gaming league and I want to write a query that will return to me the top 3 players in every game on a given event night.

Here is my table:
Columns in our table
I think I have a query that does this, but shows all finishers:

SELECT SUM(points) AS totalpoints, player, game, eventdate FROM `jos_poker_stats6` WHERE eventdate > '2011-02-28' GROUP BY player, game, eventdate ORDER BY eventdate, game, totalpoints DESC

But of course, this gives everyone.  I'm filtering this query too so that it only shows games from this past month's activity.

In PHP I could pretty easily just take the first three of every event date I guess, but thought there may be a way to do this in the query.

You can see the results below as written.

 
AS WRITTEN:

totalpointsnSSplayer      gameeventdate   
13  Samcro      1  2011-03-01  
9   halo        1  2011-03-01  
8   Paulette    1  2011-03-01  
7   trippy1976  1  2011-03-01  
6   mark        1  2011-03-01  
5   Kevin       1  2011-03-01  
4   Lepton      1  2011-03-01  
3   Wayno       1  2011-03-01  
2   Bucky       1  2011-03-01  
1   Tom         1  2011-03-01  
1   Betty       1  2011-03-01  
1   Jim         1  2011-03-01  
18  Kevin       2  2011-03-01  
9   SAMCRO      2  2011-03-01  
8   Paulette    2  2011-03-01  
7   Lepton      2  2011-03-01  
6   Tom         2  2011-03-01  
5   Wayno       2  2011-03-01  
4   Betty       2  2011-03-01  
3   Omie        2  2011-03-01  
2   halo        2  2011-03-01  
1   Remmy       2  2011-03-01  
...

WHAT I WANT:
totalpointsnSSplayer      gameeventdate   
13  Samcro      1  2011-03-01  
9   halo        1  2011-03-01  
8   Paulette    1  2011-03-01  
18  Kevin       2  2011-03-01  
9   SAMCRO      2  2011-03-01  
8   Paulette    2  2011-03-01

Open in new window

LVL 4
trippy1976Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

scifo_dkCommented:
Hi trippy1976.

I don't know what you want to do with these data, but you could create a query for each date, and then use a limit in the SQL sentence like this:
SELECT SUM(points) AS totalpoints, player, game, eventdate FROM `jos_poker_stats6` WHERE eventdate = '2011-02-28' GROUP BY player, game, eventdate ORDER BY eventdate, game, totalpoints DESC LIMIT 3

Open in new window


That would give you more querys, so I don't know if it suits your needs?

//Scifo
Guy Hengel [angelIII / a3]Billing EngineerCommented:
in mysql, you cannot really do that efficiently. it is possible, though:
http://www.experts-exchange.com/Programming/Languages/SQL_Syntax/A_1555-Analytical-SQL-Where-do-you-rank.html

if you don't want to use those technique(s), take your query, and order by the week and game, and do the "limit" in the php code by counting up to three for each week/game

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SharathData EngineerCommented:
You need to generate a row number for every record. Can you post some sample data from the table?
trippy1976Author Commented:
I ended up just brute forcing it in PHP.  I don't think I can do what I was trying in a single query based on replies
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.