S
StevenSLO
To anyone that can help:
I am trying to write a "team record" query from a "team" and
"team_match" tables that produce a record (sum of wins, losses, and
score) for games that have been played. One stipulation that we must
take into account in the "team record" query are forfeits which result
in a loss of 10 in the score column.
In the current query below, the negative scores are not subtracted
from the current score (a score of "0" is added) instead of
subtracting 10 ("-10"). Does anyone see a better way (the correct
way) to write a query that will incorporate the -10 score that is
stored in the "team_match" table? Thank You.
**Full-Schedule query**
SELECT m.matchID, m.date, m.time, m.tablenum,
t.team_name, tm.winner, tm.score
FROM match m INNER JOIN team_match tm
ON (m.matchid = tm.matchid)
INNER JOIN team t ON (tm.teamID = t.teamID)
CREATE VIEW Losers AS
SELECT Team_Match.TeamID, Team.Team_Name, COUNT(Team_Match.Winner)
Losses
FROM Team JOIN Team_Match ON (Team.TeamID = Team_Match.TeamID)
WHERE Team_Match.Winner = 0
GROUP BY Team_Match.TeamID, Team.Team_Name
CREATE VIEW Winners AS
SELECT Team_Match.TeamID, Team.Team_Name, COUNT(Team_Match.Winner)
Wins, SUM(Team_Match.Score) "Total Score"
FROM Team JOIN Team_Match ON (Team.TeamID = Team_Match.TeamID)
WHERE Team_Match.Winner = 1
GROUP BY Team.Team_Name, Team_Match.TeamID
CREATE VIEW "Team Record" AS
SELECT t.Team_Name, ISNULL(w.Wins, 0) Wins, ISNULL(l.Losses, 0)
Losses,
ISNULL(w.[Total Score], 0) "Total Score"
FROM (SELECT Team_Match.TeamID, Team.Team_Name,
COUNT(Team_Match.Winner) Losses
FROM Team JOIN Team_Match ON (Team.TeamID = Team_Match.TeamID)
WHERE Team_Match.Winner = 0
GROUP BY Team_Match.TeamID, Team.Team_Name) l
FULL OUTER JOIN Team t ON (l.TeamID = t.TeamID)
FULL OUTER JOIN (SELECT Team_Match.TeamID, Team.Team_Name,
COUNT(Team_Match.Winner) Wins, SUM(Team_Match.Score) "Total Score"
FROM Team JOIN Team_Match ON (Team.TeamID = Team_Match.TeamID)
WHERE Team_Match.Winner = 1 GROUP BY Team.Team_Name,
Team_Match.TeamID) w ON (t.TeamID = w.TeamID)
I am trying to write a "team record" query from a "team" and
"team_match" tables that produce a record (sum of wins, losses, and
score) for games that have been played. One stipulation that we must
take into account in the "team record" query are forfeits which result
in a loss of 10 in the score column.
In the current query below, the negative scores are not subtracted
from the current score (a score of "0" is added) instead of
subtracting 10 ("-10"). Does anyone see a better way (the correct
way) to write a query that will incorporate the -10 score that is
stored in the "team_match" table? Thank You.
**Full-Schedule query**
SELECT m.matchID, m.date, m.time, m.tablenum,
t.team_name, tm.winner, tm.score
FROM match m INNER JOIN team_match tm
ON (m.matchid = tm.matchid)
INNER JOIN team t ON (tm.teamID = t.teamID)
CREATE VIEW Losers AS
SELECT Team_Match.TeamID, Team.Team_Name, COUNT(Team_Match.Winner)
Losses
FROM Team JOIN Team_Match ON (Team.TeamID = Team_Match.TeamID)
WHERE Team_Match.Winner = 0
GROUP BY Team_Match.TeamID, Team.Team_Name
CREATE VIEW Winners AS
SELECT Team_Match.TeamID, Team.Team_Name, COUNT(Team_Match.Winner)
Wins, SUM(Team_Match.Score) "Total Score"
FROM Team JOIN Team_Match ON (Team.TeamID = Team_Match.TeamID)
WHERE Team_Match.Winner = 1
GROUP BY Team.Team_Name, Team_Match.TeamID
CREATE VIEW "Team Record" AS
SELECT t.Team_Name, ISNULL(w.Wins, 0) Wins, ISNULL(l.Losses, 0)
Losses,
ISNULL(w.[Total Score], 0) "Total Score"
FROM (SELECT Team_Match.TeamID, Team.Team_Name,
COUNT(Team_Match.Winner) Losses
FROM Team JOIN Team_Match ON (Team.TeamID = Team_Match.TeamID)
WHERE Team_Match.Winner = 0
GROUP BY Team_Match.TeamID, Team.Team_Name) l
FULL OUTER JOIN Team t ON (l.TeamID = t.TeamID)
FULL OUTER JOIN (SELECT Team_Match.TeamID, Team.Team_Name,
COUNT(Team_Match.Winner) Wins, SUM(Team_Match.Score) "Total Score"
FROM Team JOIN Team_Match ON (Team.TeamID = Team_Match.TeamID)
WHERE Team_Match.Winner = 1 GROUP BY Team.Team_Name,
Team_Match.TeamID) w ON (t.TeamID = w.TeamID)