lahmanlite/sql/allstarstartingpos.sql

54 lines
1.3 KiB
MySQL
Raw Normal View History

pragma foreign_keys = 0;
2024-01-30 02:34:07 +00:00
begin;
2024-01-31 06:09:39 +00:00
attach database 'baseball-raw.db' as 'raw';
CREATE TEMP TABLE "allstarstartingpos" (
"player" NUMERIC,
"year" NUMERIC,
"gameNum" NUMERIC,
"league" NUMERIC,
"startingPos" NUMERIC,
"gameid" text
);
insert into "allstarstartingpos"
select distinct playerid, yearid, gamenum, lgid, startingpos, gameid
from "raw".allstarfull;
2024-01-30 02:34:07 +00:00
-- fix game numbers for 1962 all-star games
update allstarstartingpos
set gamenum = 1
where gameid = 'ALS196207100';
update allstarstartingpos
set gamenum = 2
where gameid = 'NLS196207300';
2024-01-31 02:30:24 +00:00
-- rocky colavito was a reserve, not starter
delete from allstarstartingpos
2024-01-31 06:09:39 +00:00
where gameid = 'ALS196207100' and player = 'colavro01';
2024-01-31 02:30:24 +00:00
2024-01-31 06:09:39 +00:00
alter table allstarstartingpos drop column "gameid";
2024-01-30 02:34:07 +00:00
update allstarstartingpos
set startingpos = null
where startingpos = '';
delete from allstarstartingpos
where startingpos is null;
2024-01-31 06:09:39 +00:00
CREATE TABLE "allstarstartingpos" (
"player" NUMERIC,
"year" NUMERIC,
"gameNum" NUMERIC,
"league" NUMERIC,
2024-02-02 02:48:12 +00:00
"startingPos" NUMERIC check ("startingPos" in (1,2,3,4,5,6,7,8,9,10)),
2024-01-31 06:09:39 +00:00
primary key("year","gameNum","league","startingPos"),
foreign key("player","year","gameNum") references "allstars"("player","year","gameNum"),
foreign key("league") references "leagues"("ID")
);
insert into main.allstarstartingpos select distinct * from temp.allstarstartingpos;
2024-01-30 02:34:07 +00:00
commit;