lahmanlite/sql/halloffamereqs.sql

35 lines
817 B
MySQL
Raw Normal View History

pragma foreign_keys = 0;
2024-01-27 18:58:48 +00:00
begin;
2024-01-29 01:07:59 +00:00
attach database 'baseball-raw.db' as 'raw';
2024-01-31 06:09:39 +00:00
create temp table if not exists "halloffamereqs" (
2024-01-27 18:58:48 +00:00
"yearID" numeric,
"votedBy" text,
"ballots" numeric,
"needed" numeric,
2024-01-29 01:07:59 +00:00
"needed_note" text
2024-01-27 18:58:48 +00:00
);
insert into halloffamereqs
select distinct yearid, votedby, ballots, needed, "needed_note"
2024-01-29 01:07:59 +00:00
from "raw".halloffame;
2024-01-31 06:09:39 +00:00
2024-02-02 02:48:12 +00:00
update halloffamereqs
2024-02-04 22:20:07 +00:00
set
ballots = nullif(ballots,''),
needed = nullif(needed,''),
"needed_note" = nullif("needed_note",'');
2024-02-02 02:48:12 +00:00
2024-01-31 06:09:39 +00:00
create table if not exists main."halloffamereqs" (
"year" numeric,
"votedBy" text,
"ballots" numeric,
2024-02-02 02:48:12 +00:00
"needed" numeric check ("needed" <= "ballots"),
2024-01-31 06:09:39 +00:00
"needed_note" text,
primary key("year","votedBy"),
foreign key("year") references "seasons"("year")
);
insert into main.halloffamereqs select distinct * from temp.halloffamereqs;
2024-01-27 18:58:48 +00:00
commit;