lahmanlite/sql/batting.sql

43 lines
890 B
MySQL
Raw Normal View History

pragma foreign_keys = 0;
2024-01-26 20:03:29 +00:00
begin;
2024-01-31 06:09:39 +00:00
attach database 'baseball-raw.db' as 'raw';
create temp table batting as
select * from "raw".batting;
2024-01-26 20:03:29 +00:00
alter table batting drop column "lgID";
2024-01-30 03:43:52 +00:00
alter table batting drop column "teamID";
2024-01-31 06:09:39 +00:00
2024-02-01 04:37:26 +00:00
-- bbref doesn't say this guy played in 1911
delete from batting
where playerid = 'smithbu01' and yearid = 1911;
2024-01-31 06:09:39 +00:00
CREATE TABLE IF NOT EXISTS main."batting" (
"player" TEXT,
"year" NUMERIC,
"stint" NUMERIC,
"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"),
foreign key("year","player","stint") references "playerstints"("year","player","stint")
);
insert into main.batting select distinct * from temp."batting";
2024-01-26 20:03:29 +00:00
commit;