lahmanlite/sql/appearances.sql

45 lines
976 B
MySQL
Raw Normal View History

2024-01-26 19:27:58 +00:00
begin;
2024-01-31 06:09:39 +00:00
attach database 'baseball-raw.db' as 'raw';
create temp table appearances as
select * from "raw".appearances;
alter table appearances drop column "lgID";
update appearances
set teamid = 'WS9'
where teamid = 'WAS' and yearid between 1891 and 1899;
update appearances
set teamid = 'PHP'
where teamid = 'PH4' and yearid between 1890 and 1891;
2024-01-31 06:09:39 +00:00
CREATE TABLE IF NOT EXISTS "appearances" (
"year" NUMERIC,
"team" TEXT,
"player" TEXT,
"G_all" NUMERIC,
"GS" NUMERIC,
"G_batting" NUMERIC,
"G_defense" NUMERIC,
"G_p" NUMERIC,
"G_c" NUMERIC,
"G_1b" NUMERIC,
"G_2b" NUMERIC,
"G_3b" NUMERIC,
"G_ss" NUMERIC,
"G_lf" NUMERIC,
"G_cf" NUMERIC,
"G_rf" NUMERIC,
"G_of" NUMERIC,
"G_dh" NUMERIC,
"G_ph" NUMERIC,
"G_pr" NUMERIC,
PRIMARY KEY("year","team","player"),
foreign key("player") references "people"("ID"),
foreign key("year","team") references "teamseasons"("year","team")
);
insert into main.appearances select distinct * from temp.appearances;
2024-01-26 19:27:58 +00:00
commit;