lahmanlite/sql/load.sql

160 lines
3.1 KiB
MySQL
Raw Normal View History

2024-01-28 00:05:45 +00:00
BEGIN;
attach database 'baseball-transformed.db' as 'transformed';
create table if not exists "awards" (
"ID" text,
primary key("ID")
);
insert into awards
select distinct * from "transformed"."awards";
CREATE TABLE IF NOT EXISTS "franchises" (
2024-01-28 01:27:51 +00:00
"ID" TEXT,
"name" TEXT,
2024-01-28 00:05:45 +00:00
"active" TEXT,
"NAassoc" TEXT,
2024-01-28 01:27:51 +00:00
PRIMARY KEY("ID")
2024-01-28 00:05:45 +00:00
);
insert into franchises
select distinct * from "transformed"."franchises";
create table if not exists "franchiseseasons" (
2024-01-28 01:27:51 +00:00
"year" NUMERIC,
"league" TEXT,
"team" TEXT,
"franchise" TEXT,
"division" TEXT,
2024-01-28 00:05:45 +00:00
"Rank" NUMERIC,
"G" NUMERIC,
"Ghome" NUMERIC,
"W" NUMERIC,
"L" NUMERIC,
"DivWin" NUMERIC,
"WCWin" NUMERIC,
"LgWin" NUMERIC,
"WSWin" NUMERIC,
"R" NUMERIC,
"AB" NUMERIC,
"H" NUMERIC,
"2B" NUMERIC,
"3B" NUMERIC,
"HR" NUMERIC,
"BB" NUMERIC,
"SO" NUMERIC,
"SB" NUMERIC,
"CS" NUMERIC,
"HBP" NUMERIC,
"SF" NUMERIC,
"RA" NUMERIC,
"ER" NUMERIC,
"ERA" NUMERIC,
"CG" NUMERIC,
"SHO" NUMERIC,
"SV" NUMERIC,
"IPouts" NUMERIC,
"HA" NUMERIC,
"HRA" NUMERIC,
"BBA" NUMERIC,
"SOA" NUMERIC,
"E" NUMERIC,
"DP" NUMERIC,
"FP" NUMERIC,
"name" NUMERIC,
"park" NUMERIC,
"attendance" NUMERIC,
"BPF" NUMERIC,
"PPF" NUMERIC,
"teamIDBR" TEXT,
"teamIDlahman45" TEXT,
"teamIDretro" TEXT,
2024-01-28 01:27:51 +00:00
PRIMARY KEY("year","franchise"),
foreign key("year") references "seasons"("year"),
foreign key("franchise") references "franchises"("ID")
2024-01-28 00:05:45 +00:00
);
insert into franchiseseasons
select distinct * from "transformed"."franchiseseasons";
create table if not exists "seasons" (
"year" numeric,
primary key("year")
);
insert into seasons
select distinct * from "transformed"."seasons";
CREATE TABLE "people" (
2024-01-28 01:27:51 +00:00
"ID" text,
2024-01-28 00:05:45 +00:00
"birthYear" NUMERIC,
"birthMonth" NUMERIC,
"birthDay" NUMERIC,
"birthCountry" text,
"birthState" text,
"birthCity" text,
"deathYear" text,
"deathMonth" text,
"deathDay" text,
"deathCountry" text,
"deathState" text,
"deathCity" text,
"nameFirst" text,
"nameLast" text,
"nameGiven" text,
"weight" NUMERIC,
"height" NUMERIC,
"bats" text,
"throws" text,
"debut" text,
"finalGame" text,
"retroID" text,
"bbrefID" text,
2024-01-28 01:27:51 +00:00
primary key("ID")
2024-01-28 00:05:45 +00:00
);
INSERT INTO "people" SELECT DISTINCT * FROM "transformed"."people";
2024-01-28 00:59:05 +00:00
CREATE TABLE IF NOT EXISTS "parks" (
2024-01-28 01:27:51 +00:00
"ID" TEXT,
"name" TEXT,
2024-01-28 00:59:05 +00:00
"city" TEXT,
"state" TEXT,
"country" TEXT,
2024-01-28 01:27:51 +00:00
PRIMARY KEY("ID")
2024-01-28 00:59:05 +00:00
);
insert into "parks" select distinct * from "transformed"."parks";
CREATE TABLE IF NOT EXISTS "parkaliases" (
2024-01-28 01:27:51 +00:00
"park" TEXT,
2024-01-28 00:59:05 +00:00
"alias" TEXT,
2024-01-28 01:27:51 +00:00
PRIMARY KEY("park","alias"),
foreign key("park") references "parks"("ID")
2024-01-28 00:59:05 +00:00
);
insert into "parkaliases" select distinct * from "transformed"."parkaliases";
2024-01-28 01:14:33 +00:00
CREATE TABLE IF NOT EXISTS "collegeplaying" (
2024-01-28 01:27:51 +00:00
"player" TEXT,
"school" TEXT,
"year" NUMERIC,
PRIMARY KEY("player","year","school"),
foreign key("player") references "people"("ID"),
foreign key("school") references "schools"("ID")
2024-01-28 01:14:33 +00:00
);
insert into collegeplaying select distinct * from "transformed"."collegeplaying";
2024-01-28 01:27:51 +00:00
CREATE TABLE IF NOT EXISTS "schools" (
"ID" TEXT,
"name_full" TEXT,
"city" TEXT,
"state" TEXT,
"country" TEXT,
PRIMARY KEY("ID")
);
insert into schools select distinct * from "transformed"."schools";
2024-01-28 00:05:45 +00:00
COMMIT;