MySQL Forums
Forum List  »  Newbie

sum top 5 question
Posted by: erik beekman
Date: April 28, 2016 04:34AM

I have a question about the sum of the top 5 scores.
the code below works but sums all scores and i need only the top 5 scores.
and the selections needs to be year 2016.
i cant figure it out please need some help

erik

Table looks like this:

scores
scid
lidnr
score
dicipline
date

i got this code:

SELECT r.lidnr AS lidnr,
(SELECT Sum(r2.score) FROM scores r2
WHERE r2.lidnr = r.lidnr ORDER BY r2.score DESC LIMIT 5) AS sub,
r.dicipline AS dicipline,
r.score AS score
FROM scores r
GROUP BY r.lidnr,
r.dicipline,
r.score,
(SELECT Sum(r2.score) FROM scores r2 WHERE r2.lidnr = r.lidnr LIMIT 5)
ORDER BY (SELECT Sum(r2.score) FROM scores r2
WHERE r2.lidnr = r.lidnr LIMIT 5) DESC,
dicipline DESC

Options: ReplyQuote


Subject
Written By
Posted
sum top 5 question
April 28, 2016 04:34AM
April 28, 2016 01:28PM
April 29, 2016 08:33AM
May 02, 2016 02:33AM
May 02, 2016 09:58AM
May 03, 2016 07:05AM
May 03, 2016 09:23AM
May 04, 2016 06:51AM
May 04, 2016 11:48AM
May 04, 2016 11:39PM
May 05, 2016 11:24AM
May 05, 2016 12:31PM
May 04, 2016 11:12PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.