hello all
I'm not sure if I have gone down the wrong path here but this is what I want to do. I have a table with the following fields.
id,hp1id,hp1name,hp2id,hp2name,hp3id,hp3name,hp1s, hp2s,hp3s,ap1id,ap1name,ap2id,ap2name,ap3id,ap3nam e,ap1s,ap2s,ap3s,hpb,apb,htotal,atotal,fixtureid,s eason,leagueid
The table stores data from a scorecard from snooker games. A scorecard looks like this:
Scorecard | Cynghrair Snwcer Ceredigion Snooker League
Now then, I want to be able to display alist of all the players with their total scores and games played etc. Problem is a player can be hp1id or hp2id or hp3id or ap1id or ap2id or ap3id (hp1 means home player 1 and so on.).
I can successfully retrieve one players resutls (i.e playerid 47) and do the necessary artihmetic, based on a player id like this:
select COALESCE(sum(hp1s),0) + (select COALESCE(sum(hp2s),0)from scorecard where hp2id = 47) + (select COALESCE(sum(hp3s),0)from scorecard where hp3id = 47)+ (select COALESCE(sum(ap1s),0)from scorecard where ap1id = 47)+ (select COALESCE(sum(ap2s),0)from scorecard where ap2id = 47) + (select COALESCE(sum(ap3s),0)from scorecard where ap3id = 47)as totalscore , (select count(*) * 3 as totalgames from scorecard where hp1id = 47 or hp2id = 47 or hp3id = 47 or ap1id = 47 or ap2id = 47 or ap3id = 47
)from scorecard where hp1id = 47
But how do I get the results for all the other players like player 48, 49 50 etc? I need to order the final results too by games won, games lost, games played etc.
I have another table with playerids in if that helps.
Thanks, hope this makes sense.