move batting, pitching, fielding

This commit is contained in:
Nick Griffey 2024-01-27 19:59:00 -06:00
parent 0c4d00ddfc
commit f47e756cc0
8 changed files with 95 additions and 101 deletions

View File

@ -9,7 +9,7 @@ baseball.db: baseball-transformed.db sql/load.sql
cat sql/load.sql | sqlite3 baseball.db cat sql/load.sql | sqlite3 baseball.db
sqlite3 baseball.db "VACUUM" sqlite3 baseball.db "VACUUM"
baseball-transformed.db: baseball-raw.db sql/awards.sql sql/franchises.sql sql/franchiseseasons.sql sql/seasons.sql sql/parks.sql sql/collegeplaying.sql sql/schools.sql sql/people.sql sql/salaries.sql baseball-transformed.db: baseball-raw.db sql/awards.sql sql/franchises.sql sql/franchiseseasons.sql sql/seasons.sql sql/parks.sql sql/collegeplaying.sql sql/schools.sql sql/people.sql sql/salaries.sql sql/batting.sql sql/pitching.sql sql/fielding.sql
rm -f baseball-transformed.db rm -f baseball-transformed.db
cp baseball-raw.db baseball-transformed.db cp baseball-raw.db baseball-transformed.db
cat sql/franchises.sql | sqlite3 baseball-transformed.db cat sql/franchises.sql | sqlite3 baseball-transformed.db
@ -20,6 +20,9 @@ baseball-transformed.db: baseball-raw.db sql/awards.sql sql/franchises.sql sql/f
cat sql/collegeplaying.sql | sqlite3 baseball-transformed.db cat sql/collegeplaying.sql | sqlite3 baseball-transformed.db
cat sql/schools.sql | sqlite3 baseball-transformed.db cat sql/schools.sql | sqlite3 baseball-transformed.db
cat sql/salaries.sql | sqlite3 baseball-transformed.db cat sql/salaries.sql | sqlite3 baseball-transformed.db
cat sql/batting.sql | sqlite3 baseball-transformed.db
cat sql/pitching.sql | sqlite3 baseball-transformed.db
cat sql/fielding.sql | sqlite3 baseball-transformed.db
baseball-raw.db: baseball-raw.db:
rm -f baseball-raw.db rm -f baseball-raw.db

View File

@ -1,32 +0,0 @@
begin;
CREATE TABLE IF NOT EXISTS "pk_batting" (
"playerID" TEXT,
"yearID" NUMERIC,
"stint" NUMERIC,
"teamID" TEXT,
"lgID" TEXT,
"G" NUMERIC,
"AB" NUMERIC,
"R" NUMERIC,
"H" NUMERIC,
"2B" NUMERIC,
"3B" NUMERIC,
"HR" NUMERIC,
"RBI" NUMERIC,
"SB" NUMERIC,
"CS" NUMERIC,
"BB" NUMERIC,
"SO" NUMERIC,
"IBB" NUMERIC,
"HBP" NUMERIC,
"SH" NUMERIC,
"SF" NUMERIC,
"GIDP" NUMERIC,
PRIMARY KEY("playerID","yearID","stint","teamID"),
foreign key("playerID") references "people"("playerID")
);
INSERT INTO "pk_batting" SELECT DISTINCT * FROM "batting";
DROP TABLE "batting";
ALTER TABLE "pk_batting" RENAME TO "batting";
commit;

View File

@ -1,28 +0,0 @@
BEGIN;
CREATE TABLE IF NOT EXISTS "pk_fielding" (
"playerID" TEXT,
"yearID" NUMERIC,
"stint" NUMERIC,
"teamID" TEXT,
"lgID" TEXT,
"POS" TEXT,
"G" NUMERIC,
"GS" NUMERIC,
"InnOuts" NUMERIC,
"PO" NUMERIC,
"A" NUMERIC,
"E" NUMERIC,
"DP" NUMERIC,
"PB" NUMERIC,
"WP" NUMERIC,
"SB" NUMERIC,
"CS" NUMERIC,
"ZR" NUMERIC,
PRIMARY KEY("playerID","yearID","stint","teamID","POS"),
foreign key("playerID") references "people"("playerID")
);
INSERT INTO "pk_fielding" SELECT DISTINCT * FROM "fielding";
DROP TABLE "fielding";
ALTER TABLE "pk_fielding" RENAME TO "fielding";
COMMIT;

View File

@ -1,40 +0,0 @@
BEGIN;
CREATE TABLE IF NOT EXISTS "pk_pitching" (
"playerID" TEXT,
"yearID" NUMERIC,
"stint" NUMERIC,
"teamID" TEXT,
"lgID" TEXT,
"W" NUMERIC,
"L" NUMERIC,
"G" NUMERIC,
"GS" NUMERIC,
"CG" NUMERIC,
"SHO" NUMERIC,
"SV" NUMERIC,
"IPouts" NUMERIC,
"H" NUMERIC,
"ER" NUMERIC,
"HR" NUMERIC,
"BB" NUMERIC,
"SO" NUMERIC,
"BAOpp" NUMERIC,
"ERA" NUMERIC,
"IBB" NUMERIC,
"WP" NUMERIC,
"HBP" NUMERIC,
"BK" NUMERIC,
"BFP" NUMERIC,
"GF" NUMERIC,
"R" NUMERIC,
"SH" NUMERIC,
"SF" NUMERIC,
"GIDP" NUMERIC,
PRIMARY KEY("playerID","yearID","stint","teamID"),
foreign key("playerID") references "people"("playerID")
);
INSERT INTO "pk_pitching" SELECT DISTINCT * FROM "pitching";
DROP TABLE "pitching";
ALTER TABLE "pk_pitching" RENAME TO "pitching";
COMMIT;

View File

@ -168,4 +168,95 @@ CREATE TABLE IF NOT EXISTS "salaries" (
); );
insert into salaries select distinct * from "transformed"."salaries"; insert into salaries select distinct * from "transformed"."salaries";
CREATE TABLE IF NOT EXISTS "batting" (
"player" TEXT,
"year" NUMERIC,
"stint" NUMERIC,
"team" TEXT,
"G" NUMERIC,
"AB" NUMERIC,
"R" NUMERIC,
"H" NUMERIC,
"2B" NUMERIC,
"3B" NUMERIC,
"HR" NUMERIC,
"RBI" NUMERIC,
"SB" NUMERIC,
"CS" NUMERIC,
"BB" NUMERIC,
"SO" NUMERIC,
"IBB" NUMERIC,
"HBP" NUMERIC,
"SH" NUMERIC,
"SF" NUMERIC,
"GIDP" NUMERIC,
PRIMARY KEY("player","year","stint","team"),
foreign key("player") references "people"("ID"),
foreign key("year") references "seasons"("year")
);
insert into batting select distinct * from "transformed"."batting";
CREATE TABLE IF NOT EXISTS "fielding" (
"player" TEXT,
"year" NUMERIC,
"stint" NUMERIC,
"team" TEXT,
"POS" TEXT,
"G" NUMERIC,
"GS" NUMERIC,
"InnOuts" NUMERIC,
"PO" NUMERIC,
"A" NUMERIC,
"E" NUMERIC,
"DP" NUMERIC,
"PB" NUMERIC,
"WP" NUMERIC,
"SB" NUMERIC,
"CS" NUMERIC,
"ZR" NUMERIC,
PRIMARY KEY("player","year","stint","team","POS"),
foreign key("player") references "people"("ID"),
foreign key("year") references "seasons"("year")
);
insert into fielding select distinct * from "transformed"."fielding";
CREATE TABLE IF NOT EXISTS "pitching" (
"player" TEXT,
"year" NUMERIC,
"stint" NUMERIC,
"team" TEXT,
"W" NUMERIC,
"L" NUMERIC,
"G" NUMERIC,
"GS" NUMERIC,
"CG" NUMERIC,
"SHO" NUMERIC,
"SV" NUMERIC,
"IPouts" NUMERIC,
"H" NUMERIC,
"ER" NUMERIC,
"HR" NUMERIC,
"BB" NUMERIC,
"SO" NUMERIC,
"BAOpp" NUMERIC,
"ERA" NUMERIC,
"IBB" NUMERIC,
"WP" NUMERIC,
"HBP" NUMERIC,
"BK" NUMERIC,
"BFP" NUMERIC,
"GF" NUMERIC,
"R" NUMERIC,
"SH" NUMERIC,
"SF" NUMERIC,
"GIDP" NUMERIC,
PRIMARY KEY("player","year","stint","team"),
foreign key("player") references "people"("ID"),
foreign key("year") references "seasons"("year")
);
insert into pitching select distinct * from "transformed"."pitching";
COMMIT; COMMIT;