I have a college football database where I want to list yearly team summaries which includes the each year played with the coach and number of wins, losses, and ties. There is sometimes more than 1 coach for a season which is where I am having problems. I got the code to work for a single coach and it is here:
SELECT
games.year AS year,
coach.longname AS coach1,
SUM(games.wlt='W') AS win,
SUM(games.wlt='L') AS loss,
SUM(games.wlt='T') AS tie
from games, yearly, coach
where games.team1 = '$team'
and games.team1 = yearly.team
and games.year = yearly.year
and yearly.coach1 = coach.coachid
group by games.year
order by games.year
This code works fine but I can't get the code to work when I add another column in the yearly table for coach2
Here is the code I am trying with no luck:
SELECT
games.year AS year,
coach.longname AS coach1,
coach.longname AS coach2,
SUM(games.wlt='W') AS win,
SUM(games.wlt='L') AS loss,
SUM(games.wlt='T') AS tie
from games, yearly, coach
where games.team1 = '$team'
and games.team1 = yearly.team
and games.year = yearly.year
and yearly.coach1 = coach.coachid
and yearly.coach2 = coach.coachid
group by games.year
order by games.year
I think I am missing a basic concept that I need. Can anyone point me in the right direction?
David