country
----------
countryid
pooleid
countryname
pool
------------
pooleid
poulename
game
------------
gameid
pooleid
homecountyid
awaycountyid
prediction
------------
predictionid
userid
gameid
scorehome
scoreaway
predictedscores
---------------
userid
gameid
countryid
score (0, 1, or 3)
I'm working on a footballpool and need a query that gives me the
1. the countrynames
2. sum of the predicted scores as a ranking
for a certain user for a certain pool based on his / hers predictions.
this is what i got sofar:
all i need to now is somehow sum the score field (from predictedscores) for each coutry.
The question is ... how?
----------
countryid
pooleid
countryname
pool
------------
pooleid
poulename
game
------------
gameid
pooleid
homecountyid
awaycountyid
prediction
------------
predictionid
userid
gameid
scorehome
scoreaway
predictedscores
---------------
userid
gameid
countryid
score (0, 1, or 3)
I'm working on a footballpool and need a query that gives me the
1. the countrynames
2. sum of the predicted scores as a ranking
for a certain user for a certain pool based on his / hers predictions.
this is what i got sofar:
Code:
SELECT c1.countryname AS homecountry,
c2.countryname AS awaycountry,
p.pouleid
FROM country AS c1
INNER JOIN game AS g ON c1.countryid = g.homecountyid
INNER JOIN country AS c2 ON g.awaycountryid = c2.countryid
INNER JOIN predictedscores AS v ON g.gameid = v.gameid
INNER JOIN pool AS p ON g.poolid = p.poolid
INNER JOIN user AS U ON v.userid = u.userid
and p.pouleid = 1
and u.userid = 1
The question is ... how?