MySQL Forums
Forum List  »  Newbie

Re: SUM problem.
Posted by: Patric Andersson
Date: March 17, 2009 06:31PM

Peter,

I've read the manual about JOINs but the thing is, I don't understand it :(
I understand the SELECT you made where I get the deltagare and points and only 2 highest scores, that part I understand why and it makes perfect sence to me.

My problem however is that I need information from all 3 of my tables in order to sort it correctly (atleast I think I do).

Why I need info from lepok_anvandare is because I need the name of the persons with the 'deltagare' id (lepok_anvandare.id = lepok_resultat.deltagare).
I allso need the info from lepok_turnering (as the type of torney is saved there, and I only want the result from the torneys saved with the key "typ=pligan" and I need the year from when the torney was played so it only shows the result from the current years torneys and not add old ones)

In the code you wrote :
SELECT a.deltagare, a.poang, count(*) AS higher
FROM lepok_resultat a
JOIN lepok_resultat b ON a.deltagare=b.deltagare AND a.poang <= b.poang
GROUP BY a.deltagare, a.poang
HAVING higher <= 2
ORDER BY a.deltagare,higher ;
Changeing the last line to
ORDER BY SUM(a.poang);
And then printing SUM(a.poang) would that only SUM the 2 top results or would it SUM all 3?
That I change the ORDER BY is just so that the one with the highest SUM should be printed first.

And btw, is there a jawa script engine (or similar) on this site (or other site) where you could just input the CREATE TABLE that I printed in the earlier post to try out different SELECTs ? (trial and error ftw :P)

So the quests this time...
1) Can you get information from 3 different tables but only join 1 of em ?
2) In above example, SUM(a.poang) would it only calculate the top 2 results or would it actually calculate all 3 ?
3) Does a easy web based plugin to test code exist?

I think that's all for right now, and sorry for being such a pain in the ass and asking stupied questions, but I'm trying to understand this and I really appriciate (spelling) your help :)

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
March 16, 2009 02:46PM
March 16, 2009 04:15PM
March 17, 2009 02:11PM
March 17, 2009 05:03PM
Re: SUM problem.
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.