add teamcodes table

This commit is contained in:
Nick Griffey 2024-01-27 21:19:48 -06:00
parent b30302eea6
commit 9f0ac4098b
3 changed files with 29 additions and 1 deletions

View File

@ -9,7 +9,7 @@ baseball.db: baseball-transformed.db sql/load.sql
cat sql/load.sql | sqlite3 baseball.db
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 sql/batting.sql sql/pitching.sql sql/fielding.sql sql/appearances.sql sql/homegames.sql sql/seriespost.sql sql/fieldingofsplit.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 sql/appearances.sql sql/homegames.sql sql/seriespost.sql sql/fieldingofsplit.sql sql/teamcodes.sql
rm -f baseball-transformed.db
cp baseball-raw.db baseball-transformed.db
cat sql/franchises.sql | sqlite3 baseball-transformed.db
@ -28,6 +28,7 @@ baseball-transformed.db: baseball-raw.db sql/awards.sql sql/franchises.sql sql/f
cat sql/people.sql | sqlite3 baseball-transformed.db
cat sql/seriespost.sql | sqlite3 baseball-transformed.db
cat sql/fieldingofsplit.sql | sqlite3 baseball-transformed.db
cat sql/teamcodes.sql | sqlite3 baseball-transformed.db
baseball-raw.db:
rm -f baseball-raw.db

View File

@ -342,4 +342,13 @@ CREATE TABLE IF NOT EXISTS "fieldingofsplit" (
);
insert into fieldingofsplit select distinct * from "transformed"."fieldingofsplit";
create table if not exists teamcodes (
"team" text,
"franchise" text,
primary key("team"),
foreign key("franchise") references "franchises"("ID")
);
insert into teamcodes select distinct * from "transformed"."teamcodes";
COMMIT;

18
sql/teamcodes.sql Normal file
View File

@ -0,0 +1,18 @@
begin;
attach database 'baseball-raw.db' as 'raw';
create table if not exists teamcodes (
"team" text,
"franchise" text
);
insert into teamcodes
select distinct teamid, franchid from "raw"."teams";
update teamcodes
set team = 'WS9'
where team = 'WAS' and franchise = 'WAS';
update teamcodes
set team = 'PHP'
where team = 'PH4' and franchise = 'PHQ';
commit;