table:
hometeam awayteam homepoints awaypoints
leeds man u 3 0
leeds man u 3 0
man u leeds 0 3
i want to calculate how many points each team has. with the above data leeds should have 9 and man u 0. i have come up wth the following sql code to work this out:
select hometeam, sum(homepoints)
from fixtures
group by hometeam
union
select awayteam, sum(awaypoints)
from fixtures
group by awayteam
this code almost does it but i get the following result:
hometeam sum(homepoints)
Leeds 6
Man Utd 0
Leeds 3
i need it to show each team only once(distinct) and sum the points. how do i get the following results:
hometeam sum(homepoints)
Leeds 9
Man Utd 0
any question please ask. thanks for your help