Sei sulla pagina 1di 5

To help you try out the code in this book, we are providing a copy of the Baseball Databank database.

This file is based on the 12-30-2005 release of the databse, and includes data through the end of the 2005 season. You can get more information about this database from http://www.baseball-databank.org For reference, I have also posted the script that I used to create this file. You do not need to run this script, unless you want to get a copy of the database directly from the Baseball Databank web site. Here are some simple instructions on how to load this file into your computer: 1. Install MySQL 2. Download the file bbdb.sql.gz 3. Decompress the file. a. On Microsoft Windows, I recommend using WinZip to unpack this file. You can get a copy of this progrma from http://www.winzip.com b. On Linux, MacOS, and other Unix-like platforms, use gunzip to unpack this file. You can use a command like this to unpzck the file: > gunzip bbdb.sql.gz 4. Create a new MySQL database. You can do this with a set of commands like this (note that I called the database "example"): $ mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 190 to server version: 5.0.15-nt Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> grant ALL on example.* to 'you'@'localhost'; Query OK, 0 rows affected (0.03 sec) mysql> create database example; Query OK, 1 row affected (0.00 sec) mysql> quit; 5. Load the file into the database. You can do this with a command like this: $ mysql -s example < bbdb.sql 6. Check that everything is there: mysql> show tables; +-------------------+ Tables_in_example +-------------------+ allstar awardsvotes awardswinners batting

fielding fieldingof managers managershalf master pitching salaries teams teamsfranchises teamshalf transactions +-------------------+ 15 rows in set (0.00 sec) mysql> select count(*) from allstar; +----------+ count(*) +----------+ 4115 +----------+ 1 row in set (0.05 sec) mysql> select count(*) from awardsvotes; +----------+ count(*) +----------+ 6211 +----------+ 1 row in set (0.01 sec) mysql> select count(*) from awardswinners; +----------+ count(*) +----------+ 2430 +----------+ 1 row in set (0.00 sec) mysql> select count(*) from batting; +----------+ count(*) +----------+ 87308 +----------+ 1 row in set (0.37 sec) mysql> select count(*) from fielding; +----------+ count(*) +----------+ 126130 +----------+ 1 row in set (0.49 sec) mysql> select count(*) from fieldingof; +----------+ count(*) +----------+ 21602 +----------+

1 row in set (0.15 sec) mysql> select count(*) from managers; +----------+ count(*) +----------+ 3067 +----------+ 1 row in set (0.05 sec) mysql> select count(*) from managershalf; +----------+ count(*) +----------+ 95 +----------+ 1 row in set (0.05 sec) mysql> select count(*) from master; +----------+ count(*) +----------+ 16566 +----------+ 1 row in set (0.17 sec) mysql> select count(*) from pitching; +----------+ count(*) +----------+ 36898 +----------+ 1 row in set (0.20 sec) mysql> select count(*) from salaries; +----------+ count(*) +----------+ 17277 +----------+ 1 row in set (0.14 sec) mysql> select count(*) from teams; +----------+ count(*) +----------+ 2505 +----------+ 1 row in set (0.06 sec) mysql> select count(*) from teamsfranchises; +----------+ count(*) +----------+ 120 +----------+ 1 row in set (0.00 sec) mysql> select count(*) from teamshalf; +----------+

count(*) +----------+ 52 +----------+ 1 row in set (0.00 sec) mysql> select count(*) from transactions; +----------+ count(*) +----------+ 0 +----------+ 1 row in set (0.00 sec) And that's it! You should be ready to start calculating baseball statistics. You should now be able to run queries like this: $ mysql example Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 195 to server version: 5.0.15-nt Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> create temporary table h -> as select idxLahman, sum(hr) as hr -> from batting -> group by idxLahman; Query OK, 16416 rows affected (1.32 sec) Records: 16416 Duplicates: 0 Warnings: 0 mysql> create index h_idx on h(idxLahman); Query OK, 16416 rows affected (0.51 sec) Records: 16416 Duplicates: 0 Warnings: 0 mysql> select m.nameLast, m.nameFirst, h.hr -> from master m inner join h -> on m.idxLahman=h.idxLahman -> where hr > 500; +-----------+-----------+------+ nameLast nameFirst hr +-----------+-----------+------+ Aaron Hank 755 Banks Ernie 512 Bonds Barry 708 Foxx Jimmie 534 Griffey Ken 536 Jackson Reggie 563 Killebrew Harmon 573 Mantle Mickey 536 Mathews Eddie 512 Mays Willie 660 McCovey Willie 521 McGwire Mark 583 Murray Eddie 504 Ott Mel 511 Palmeiro Rafael 569 Robinson Frank 586 Ruth Babe 714 Schmidt Mike 548 Sosa Sammy 588

Williams Ted 521 +-----------+-----------+------+ 20 rows in set (0.11 sec)------------153DE698B73C7--------------A71642E11F26F9B-

Potrebbero piacerti anche