Here's a quick and dirty one for standings. Actually I'd love to put some more expanded data, like team runs scored and allowed, but as before this data won't get pushed into the DB until the season is over...
This is the American League West, home of more or less the only really close pennant race in my league (both NL teams have clinched and the Cleveland Indians lead the AL East by a relatively comfortable 5 games, although they still haven't quite clinched yet).
Code:
name w l gb pct
Minnesota Twins 88 66 0 0.5714
Chicago White Sox 86 68 2 0.5584
California Angels 78 76 10 0.5065
Kansas City Royals 67 87 21 0.4351
Seattle Pilots 64 90 24 0.4156
Oakland Athletics 47 107 41 0.3052
Code:
set @subleague = 0, @division=1;
SELECT concat(tm.name, ' ', tm.nickname) as name,
tr.w,
tr.l,
tr.gb,
tr.pct
FROM `modern-ish-baseball`.teams tm
LEFT JOIN team_record tr
on tr.team_id = tm.team_id
where
tm.league_id = 100
and tm.sub_league_id = @subleague
and tm.division_id = @division
order by gb
Here I didn't even need to do any calculations. There are ways to create a temp table with your list of subleagues and divisions and iterate over it to produce the standings but I don't really feel like doing that (haha) and TBH I think if you're designing an API or whatever the formatting is not as important as the data itself (for the latter, you could easily modify this to export the teams' subleague and division ids along with the names of those).
Oh, also, your league_id 100 team is going to be the first league you created. Unless you did something screwy with your league setup, you can probably get away with hardcoding that...