lahmanlite/sql/pitching.sql

48 lines
1.0 KiB
MySQL
Raw Normal View History

pragma foreign_keys = 0;
pragma ignore_check_constraints = 1;
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 pitching as
select * from "raw".pitching;
2024-01-26 20:03:29 +00:00
alter table pitching drop column "lgID";
2024-01-30 03:43:52 +00:00
alter table pitching drop column "teamID";
2024-01-31 06:09:39 +00:00
CREATE TABLE IF NOT EXISTS main."pitching" (
"player" TEXT,
"year" NUMERIC,
"stint" NUMERIC,
"W" NUMERIC,
"L" NUMERIC,
"G" NUMERIC check (W + L + SV <= G),
"GS" NUMERIC check (GS <= G),
"CG" NUMERIC check (CG <= GS),
"SHO" NUMERIC check (SHO <= CG),
2024-01-31 06:09:39 +00:00
"SV" NUMERIC,
"IPouts" NUMERIC,
"H" NUMERIC,
"ER" NUMERIC check (ER <= R),
2024-01-31 06:09:39 +00:00
"HR" NUMERIC,
"BB" NUMERIC,
"SO" NUMERIC,
"BAOpp" NUMERIC,
"ERA" NUMERIC,
"IBB" NUMERIC,
"WP" NUMERIC,
"HBP" NUMERIC,
"BK" NUMERIC,
"BFP" NUMERIC,
"GF" NUMERIC,
"R" 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.pitching select distinct * from temp."pitching";
2024-01-26 20:03:29 +00:00
commit;