Query Library

Casey Trauer submitted this query on: July 23, 2008 4:23pm EDT
TITLE Get overall standings For one MLB team
SPORTS Baseball
QUERY SELECT 

display_names_team.first_name,
display_names_team.last_name,
outcome_totals.rank,
outcome_totals.events_played,
outcome_totals.wins,
outcome_totals.losses,
outcome_totals.games_back

FROM standings
JOIN standing_subgroups ON standing_subgroups.standing_id = standings.id
JOIN affiliations ON affiliations.id = standing_subgroups.affiliation_id
JOIN sub_seasons ON sub_seasons.id = standings.sub_season_id
JOIN seasons ON seasons.id = sub_seasons.season_id

JOIN outcome_totals ON outcome_totals.standing_subgroup_id = standing_subgroups.id
JOIN teams ON teams.id = outcome_totals.outcome_holder_id
JOIN display_names AS display_names_team ON display_names_team.entity_id = teams.id

WHERE teams.team_key = 'l.mlb.com-t.1' 
AND standing_subgroups.competition_scope = 'all'
AND standing_subgroups.alignment_scope IS NULL
AND seasons.season_key = '2008'
AND display_names_team.entity_type = 'teams'
ORDER BY outcome_totals.rank ASC
DESCRIPTION Returns the division standings placement for one MLB team, using its team key.
DBs TESTED MySQL
ADDITIONAL NOTES