Query Library

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

display_names_team.first_name,
display_names_team.last_name,
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 affiliations.affiliation_key = 'd.nleast' 
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 This returns standings for a given division key. The keys are:

d.nleast
d.nlcentral
d.nlwest
d.aleast
d.alcentral
d.alwest
DBs TESTED MySQL
ADDITIONAL NOTES