MySQL Forums
Forum List  »  Newbie

Add points in many fields and one row
Posted by: King Kong
Date: May 29, 2014 08:21PM

Dear all,
another questions which I can't solve.
I have a table containing names with indices:
id---Name---index1---index2---index3---
Example
1---Maria---4---6---1
2---Klaus---8---1---3

These ids refer to another table which contains points
id---Country---name---points
Example
1---Brazil---Neymar---5
2---Argentina---Messi---10
etc.
I would like to add the points in table one for Maria.
E.g. her id=4 in column 3 could refer in table 2 to the value 11
Her id=6 in column 4 could refer in table 2 to the value 3
And her id=1 in column 5 refers to the value 5 in table 2.
So I would like to create a view where I can see:
id---Name---totalpoints
1---Maria---19
2--Klaus---34

How can I do it? The only I thing I could come up with, is only for one person, and adds up all manually, like this. Ugly and not helpful if I want to have a view with all players in one table.

Best regards
Herbert

select M.name, P.Punkte+
(select P.Punkte+
(select P.Punkte+
(select P.Punkte+
(select P.Punkte+
(select P.Punkte+
(select P.Punkte+
(select P.Punkte+
(select P.Punkte+
(select P.Punkte from Mitspieler M, view_punkte_kombiniert P where M.Player10_id=P.id and M.id=3)
from Mitspieler M, view_punkte_kombiniert P where M.Player9_id=P.id and M.id=3)
from Mitspieler M, view_punkte_kombiniert P where M.Player8_id=P.id and M.id=3)
from Mitspieler M, view_punkte_kombiniert P where M.Player7_id=P.id and M.id=3)
from Mitspieler M, view_punkte_kombiniert P where M.Player6_id=P.id and M.id=3)
from Mitspieler M, view_punkte_kombiniert P where M.Player5_id=P.id and M.id=3)
from Mitspieler M, view_punkte_kombiniert P where M.Player4_id=P.id and M.id=3)
from Mitspieler M, view_punkte_kombiniert P where M.Player3_id=P.id and M.id=3)
from Mitspieler M, view_punkte_kombiniert P where M.Player2_id=P.id and M.id=3)
from Mitspieler M, view_punkte_kombiniert P where M.Player1_id=P.id and M.id=3

Options: ReplyQuote


Subject
Written By
Posted
Add points in many fields and one row
May 29, 2014 08:21PM


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.