Database Reference
In-Depth Information
| 2 | Eastern | St. Paul | 21 | 21 | 0.500 | 1.0 |
| 2 | Eastern | Madison | 19 | 23 | 0.452 | 3.0 |
| 2 | Eastern | Thunder Bay | 18 | 24 | 0.428 | 4.0 |
| 2 | Western | Fargo-Moorhead | 26 | 16 | 0.619 | - |
| 2 | Western | Winnipeg | 24 | 18 | 0.571 | 2.0 |
| 2 | Western | Sioux City | 22 | 20 | 0.523 | 4.0 |
| 2 | Western | Sioux Falls | 16 | 26 | 0.380 | 10.0 |
+------+----------+-----------------+------+------+-------+------+
That output is difficult to read, however. To make it easier to understand, you might
execute the statement from within a program and reformat its results to display each
set of team records separately. Here's some Perl code that does that by beginning a new
output group each time it encounters a new group of standings. The code assumes that
the join statement has just been executed and that its results are available through the
statement handle $sth :
my ( $cur_half , $cur_div ) = ( "" , "" );
while ( my ( $half , $div , $team , $wins , $losses , $pct , $gb )
= $sth -> fetchrow_array ())
{
if ( $cur_half ne $half || $cur_div ne $div ) # new group of standings?
{
# print standings header and remember new half/division values
print "\n$div Division, season half $half\n" ;
printf "%-20s %3s %3s %5s %s\n" , "Team" , "W" , "L" , "PCT" , "GB" ;
$cur_half = $half ;
$cur_div = $div ;
}
printf "%-20s %3d %3d %5s %s\n" , $team , $wins , $losses , $pct , $gb ;
}
The reformatted output looks like this:
Eastern Division, season half 1
Team W L PCT GB
St. Paul 24 18 0.571 -
Thunder Bay 18 24 0.428 6.0
Duluth-Superior 17 24 0.414 6.5
Madison 15 27 0.357 9.0
Western Division, season half 1
Team W L PCT GB
Winnipeg 29 12 0.707 -
Sioux City 28 14 0.666 1.5
Fargo-Moorhead 21 21 0.500 8.5
Sioux Falls 15 27 0.357 14.5
Eastern Division, season half 2
Team W L PCT GB
Duluth-Superior 22 20 0.523 -
St. Paul 21 21 0.500 1.0
Madison 19 23 0.452 3.0
Search WWH ::




Custom Search