Jump to content

List top 5 within each group by


ded

Recommended Posts

How do I show the totals for the top 5 for each group by?

 

Example:

Joe 29

Joe 25

Joe 24

Joe 23

Joe 31

Bill 20

Bill 29

Bill 2

Bill 8

Bill 22

Scott 25

Scott 14

Scott 19

Scott 25

Scott 29

Mike 23

Mike 19

Mike 22

Mike 28

Mike 23

Bob 22

Bob 26

Bob 22

Bob 24

Bob 21

 

Total points would show the following:

Joe = 131

Mike = 115

Bob = 115

Scott = 112

Bill = 81

 

I want to rank the people by their top 3 points

Joe = 85

Scott = 79

Mike = 74

Bob = 72

Bill = 71

 

 

How is this done in SQL?

Is it possible?

 

This is my current code

SELECT *, SUM(`nationalpoints`)  
FROM `tournamentresults` 
GROUP BY `playername` 
ORDER BY SUM(`nationalpoints`) DESC

 

Regards,

David Hascup

 

Link to comment
Share on other sites

  • 2 weeks later...
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.