MySQL Forums
Forum List  »  Newbie

Re: SUM problem.
Posted by: Patric Andersson
Date: March 16, 2009 02:46PM

Ok, 3'rd time the charm then :)
Hope this is the info you need to be able to help me.
This is a simplified tables of what I currently use, but all the keys that is needed (I think).
CREATE TABLE lepok_anvandare(id int(10), fornamn varchar(255), efternamn varchar(255));

CREATE TABLE lepok_resultat(id int(10), turnering int(10), deltagare varchar(255), poang int(10));

CREATE TABLE lepok_turneringar(id int(10), datum date, typ varchar(255));

INSERT INTO lepok_anvandare VALUES ('1','Patric','Andersson'),('2','Anders','Andersson'),('3','Fredrik','Johansson');

INSERT INTO lepok_resultat VALUES ('1','1','1','10'),('2','2','1','5'),('3','3','1','12'),('4','1','2','18'),
('5','2','2','7'),('6','3','2','1'),('7','1','3','10'),('8','2','3','10'),('9','3','3','10');

INSERT INTO lepok_turneringar VALUES ('1','2008-02-10','pligan'),('2','2008-02-11','pligan'),('3','2008-02-12','pligan');
Ok, and here is the current SELECT I'm useing.
SELECT lepok_anvandare.id AS anvid, fornamn, efternamn,
typ, lepok_turneringar.id, datum, YEAR(datum), YEAR(CURRENT_DATE()),
SUM(poang), MAX(poang), deltagare, turnering
FROM lepok_anvandare, lepok_resultat, lepok_turneringar
WHERE lepok_anvandare.id=deltagare AND typ='pligan' AND lepok_turneringar.id=turnering
AND YEAR(datum)=YEAR(CURRENT_DATE())
GROUP BY lepok_anvandare.id ORDER BY SUM(poang) DESC, MAX(poang) DESC
In this temp database, it would sort the 3 users based on the 3 torneys.
But what if I wanted to sort the 3 users based on their 2 best results ?
If it's possible to write a SELECT for that, I think it should be easy for me to convert the 2 out of 3 to 8 out of 11 :)

And again, I hope this was the information you needed.

Options: ReplyQuote


Subject
Written By
Posted
March 12, 2009 03:29AM
March 12, 2009 09:52AM
March 13, 2009 07:10PM
March 13, 2009 11:10PM
March 14, 2009 04:01PM
March 14, 2009 06:40PM
March 15, 2009 07:54AM
March 15, 2009 10:41AM
March 15, 2009 10:35PM
March 16, 2009 09:33AM
March 16, 2009 09:52AM
Re: SUM problem.
March 16, 2009 02:46PM
March 16, 2009 04:15PM
March 17, 2009 02:11PM
March 17, 2009 05:03PM
March 17, 2009 06:31PM
March 17, 2009 10:17PM
March 18, 2009 06:03AM
March 15, 2009 05:41PM
March 15, 2009 07:14PM
March 16, 2009 08:34AM
March 18, 2009 12:52AM
March 21, 2009 05:58AM
March 21, 2009 11:13AM
March 22, 2009 05:01PM


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.