move teamshalf

This commit is contained in:
Nick Griffey 2024-01-29 19:48:17 -06:00
parent aba5b75ad5
commit 4e6f000d3f
6 changed files with 36 additions and 42 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/teamseasons.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/teams.sql sql/leagues.sql sql/managers.sql sql/awardsmanagers.sql sql/battingpost.sql sql/fieldingpost.sql sql/pitchingpost.sql sql/appearancespost.sql sql/awardsshareplayers.sql sql/yearlyawards.sql sql/halloffame.sql sql/halloffamereqs.sql sql/awardsplayers.sql sql/parkaliases.sql
baseball-transformed.db: baseball-raw.db sql/awards.sql sql/franchises.sql sql/teamseasons.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/teams.sql sql/leagues.sql sql/managers.sql sql/awardsmanagers.sql sql/battingpost.sql sql/fieldingpost.sql sql/pitchingpost.sql sql/appearancespost.sql sql/awardsshareplayers.sql sql/yearlyawards.sql sql/halloffame.sql sql/halloffamereqs.sql sql/awardsplayers.sql sql/parkaliases.sql sql/teamseasonshalf.sql
rm -f baseball-transformed.db
cp baseball-raw.db baseball-transformed.db
cat sql/franchises.sql | sqlite3 baseball-transformed.db
@ -42,6 +42,7 @@ baseball-transformed.db: baseball-raw.db sql/awards.sql sql/franchises.sql sql/t
cat sql/halloffamereqs.sql | sqlite3 baseball-transformed.db
cat sql/awardsplayers.sql | sqlite3 baseball-transformed.db
cat sql/parkaliases.sql | sqlite3 baseball-transformed.db
cat sql/teamseasonshalf.sql | sqlite3 baseball-transformed.db
baseball-raw.db:
rm -f baseball-raw.db

View File

@ -1,15 +0,0 @@
begin;
create table if not exists "teamshalfdivisions" (
"yearID" numeric,
"teamID" text,
"divID" text,
primary key("yearID","teamID")
);
insert into teamshalfdivisions
select distinct yearid, teamid, divid
from teamshalf;
alter table teamshalf drop column "lgID";
alter table teamshalf drop column "divID";
commit;

View File

@ -1,7 +0,0 @@
begin;
insert into teamshalf
select yearid, null, teamid, half, null, null, "rank", sum(g), sum(w), sum(l)
from managershalf
where yearid = 1892
group by yearid, teamid, half;
commit;

View File

@ -1,19 +0,0 @@
BEGIN;
CREATE TABLE IF NOT EXISTS "pk_teamshalf" (
"yearID" NUMERIC,
"lgID" TEXT,
"teamID" TEXT,
"Half" NUMERIC,
"divID" TEXT,
"DivWin" TEXT,
"Rank" NUMERIC,
"G" NUMERIC,
"W" NUMERIC,
"L" NUMERIC,
PRIMARY KEY("Half","yearID","teamID")
);
INSERT INTO "pk_teamshalf" SELECT DISTINCT * FROM "teamshalf";
DROP TABLE "teamshalf";
ALTER TABLE "pk_teamshalf" RENAME TO "teamshalf";
COMMIT;

View File

@ -578,4 +578,19 @@ CREATE TABLE IF NOT EXISTS "awardsplayers" (
);
insert into awardsplayers select distinct * from "transformed".awardsplayers;
CREATE TABLE IF NOT EXISTS "teamseasonshalf" (
"year" NUMERIC,
"team" TEXT,
"Half" NUMERIC,
"DivWin" TEXT,
"Rank" NUMERIC,
"G" NUMERIC,
"W" NUMERIC,
"L" NUMERIC,
PRIMARY KEY("year","team","Half"),
foreign key("year","team") references "teamseasons"("year","team")
);
insert into teamseasonshalf select distinct * from "transformed".teamseasonshalf;
COMMIT;

19
sql/teamseasonshalf.sql Normal file
View File

@ -0,0 +1,19 @@
begin;
attach database 'baseball-raw.db' as 'raw';
alter table teamshalf rename to "teamseasonshalf";
insert into teamseasonshalf
select yearid, null, teamid, half, null, null, "rank", sum(g), sum(w), sum(l)
from "raw".managershalf
where yearid = 1892
group by yearid, teamid, half;
update teamseasonshalf
set teamid = 'WS9'
where yearid = 1892 and teamid = 'WAS';
alter table teamseasonshalf drop column "lgID";
alter table teamseasonshalf drop column "divID";
commit;