Skip to content

Instantly share code, notes, and snippets.

@AlphaSheep
Last active December 27, 2023 11:30
Show Gist options
  • Save AlphaSheep/d1b3a5ec9517935332d27644b129afdf to your computer and use it in GitHub Desktop.
Save AlphaSheep/d1b3a5ec9517935332d27644b129afdf to your computer and use it in GitHub Desktop.
AfR Candidates
create table compdates as
select
id as competitionId,
year * 1e6 + month * 1e2 + day as date
from Competitions;
create table africans as
select
Persons.id as wcaId
from
Persons
left join Countries on Persons.countryId = Countries.id
where Countries.continentId = '_Africa';
create table african_results as
select
PersonId,
eventId,
best,
average,
date,
regionalSingleRecord,
regionalAverageRecord
from
Results
left join compdates on compdates.competitionId = Results.competitionId
where
personId in (select wcaId from africans);
create table afr_avg_dates as
select
eventId,
max(date) as afr_date
from
african_results
where
regionalAverageRecord = 'AfR'
group by
eventId;
create table afr_single_dates as
select
eventId,
max(date) as afr_date
from
african_results
where
regionalSingleRecord = 'AfR'
group by
eventId;
create table dated_african_results as
select
PersonId,
african_results.eventId as eventId,
best,
average,
date,
regionalSingleRecord,
regionalAverageRecord,
afr_avg_dates.afr_date as afr_avg_date,
afr_single_dates.afr_date as afr_single_date
from
african_results
left join afr_avg_dates on african_results.eventId = afr_avg_dates.eventId
left join afr_single_dates on african_results.eventId = afr_single_dates.eventId;
create table single_targets as
select
eventId,
min(best) as single_target
from
dated_african_results
where
date < afr_single_date - 1e6
and best > 0
group by
eventId;
create table average_targets as
select
eventId,
min(average) as average_target
from
dated_african_results
where
date < afr_avg_date - 1e6
and average > 0
group by
eventId;
create table afr_candidates as
select
personId,
dated_african_results.eventId as eventId,
best,
average,
date,
afr_avg_date,
afr_single_date,
single_target,
average_target,
if((best <= single_target and best > 0) or regionalSingleRecord = 'AfR', true, false) as single_candidate,
if((average <= average_target and average > 0) or regionalAverageRecord = 'AfR', true, false) as average_candidate
from
dated_african_results
left join single_targets on single_targets.eventId = dated_african_results.eventId
left join average_targets on average_targets.eventId = dated_african_results.eventId
where
(best <= single_target and best > 0)
or (average <= average_target and average > 0);
create table afr_candidates_summary as
select
Events.name as eventName,
personId,
Persons.name as personName,
min(best),
min(average),
case
when max(single_candidate) and max(average_candidate) then "single & average"
when max(single_candidate) and not max(average_candidate) then "single only"
when not max(single_candidate) and max(average_candidate) then "average only"
else "error"
end as single_or_average
from
afr_candidates
left join Persons on personId = Persons.id
left join Events on eventId = Events.id
where
Events.rank < 200
group by
personId,
Persons.name,
eventId,
Events.name
order by
eventId,
max(average_candidate) desc,
max(single_candidate) desc,
min(average),
min(best),
personId;
select
eventName,
single_or_average,
count(*) as num
from
afr_candidates_summary
group by
eventName,
single_or_average
'2x2x2 Cube' '2015GROB02' 'Ruben Grobler' '119' '194' 'single & average'
'2x2x2 Cube' '2018RUSH01' 'Daniel Rush' '108' '216' 'single & average'
'2x2x2 Cube' '2015BOUS02' 'Moez Boussarsar' '105' '230' 'single & average'
'2x2x2 Cube' '2022HOOG04' 'Jan-Hendrik Hoogendyk' '171' '261' 'single only'
'2x2x2 Cube' '2016HARI06' 'Shivaan Harichander' '177' '324' 'single only'
'2x2x2 Cube' '2014PEAR02' 'Maverick Pearson' '134' '334' 'single only'
'2x2x2 Cube' '2022SHAL01' 'Adam Shalaby' '195' '336' 'single only'
'2x2x2 Cube' '2019BADR01' 'Osman Badroodin' '162' '345' 'single only'
'2x2x2 Cube' '2022CLEW02' 'Charlie Cleworth' '183' '352' 'single only'
'2x2x2 Cube' '2019ANTA02' 'Ali Antar' '183' '381' 'single only'
'2x2x2 Cube' '2022ZIAD01' 'Omar Ziad' '202' '381' 'single only'
'2x2x2 Cube' '2019RAGH04' 'Rafik Sarwat Naeem Ragheb' '202' '391' 'single only'
'2x2x2 Cube' '2019RAGH04' 'Rafik Eskandar' '202' '391' 'single only'
'2x2x2 Cube' '2018LANG07' 'Andreas de Lange' '190' '396' 'single only'
'2x2x2 Cube' '2015KERK03' 'Rayan Kerkeni' '202' '406' 'single only'
'2x2x2 Cube' '2016CHAO02' 'Achraf Chaouch' '187' '407' 'single only'
'2x2x2 Cube' '2015HAGE02' 'Zaakir Hagee' '202' '420' 'single only'
'2x2x2 Cube' '2015AKOO01' 'Muhammad Akoodi' '172' '432' 'single only'
'2x2x2 Cube' '2020ROOD02' 'Chase Lee Roodt' '169' '476' 'single only'
'2x2x2 Cube' '2017NAID01' 'Keelan Naidoo' '194' '498' 'single only'
'2x2x2 Cube' '2022BORN02' 'Neels Bornman' '170' '581' 'single only'
'2x2x2 Cube' '2016KOND07' 'Christopher Kondylis' '181' '584' 'single only'
'2x2x2 Cube' '2019ELHA01' 'Yahia Ahmed Abdallah Elhawy' '202' '599' 'single only'
'2x2x2 Cube' '2016ISLE01' 'Mouhamed Islem Boukri' '131' '641' 'single only'
'2x2x2 Cube' '2019SCHE06' 'Chandler Scheurkogel' '142' '646' 'single only'
'2x2x2 Cube' '2023SWIT02' 'Caspar Switijnk' '182' '668' 'single only'
'2x2x2 Cube' '2022PARM01' 'Mrish Parmar' '190' '926' 'single only'
'3x3x3 Cube' '2018RUSH01' 'Daniel Rush' '487' '680' 'single & average'
'3x3x3 Blindfolded' '2019HOBB02' 'Duncan Hobbs' '2455' '-1' 'single & average'
'3x3x3 Blindfolded' '2017SWAR03' 'Dylan Swarts' '3038' '-1' 'single & average'
'3x3x3 Blindfolded' '2020BELA01' 'Badr Ait Belaid' '2533' '-1' 'single only'
'3x3x3 Fewest Moves' '2017LAWR04' 'Timothy Lawrance' '23' '-1' 'single & average'
'3x3x3 Fewest Moves' '2015GROB02' 'Ruben Grobler' '27' '-1' 'single & average'
'3x3x3 Fewest Moves' '2019BADR01' 'Osman Badroodin' '27' '-1' 'single & average'
'3x3x3 Fewest Moves' '2019LANG03' 'Heinrich de Lange' '31' '3500' 'single & average'
'3x3x3 Fewest Moves' '2018RUSH01' 'Daniel Rush' '33' '3533' 'average only'
'3x3x3 Fewest Moves' '2014GRAY03' 'Brendan James Gray' '30' '-1' 'single only'
'3x3x3 Fewest Moves' '2014PEAR02' 'Maverick Pearson' '31' '-1' 'single only'
'3x3x3 Fewest Moves' '2018ANAS01' 'Anass Doublal' '29' '0' 'single only'
'3x3x3 Fewest Moves' '2019MARA05' 'Joshua Christian Marais' '31' '3800' 'single only'
'3x3x3 Multi-Blind' '2019HOBB02' 'Duncan Hobbs' '760335903' '0' 'single only'
'3x3x3 Multi-Blind' '2017SWAR03' 'Dylan Swarts' '810348204' '0' 'single only'
'3x3x3 Multi-Blind' '2015FAUG01' 'Marike Faught' '840325600' '0' 'single only'
'3x3x3 One-Handed' '2019MARA05' 'Joshua Christian Marais' '1034' '1202' 'single & average'
'3x3x3 One-Handed' '2019HOOS01' 'Waseem Hoosain' '1066' '1315' 'single only'
'4x4x4 Cube' '2018RUSH01' 'Daniel Rush' '2506' '2763' 'single & average'
'4x4x4 Cube' '2019HOOS01' 'Waseem Hoosain' '2656' '3398' 'single only'
'4x4x4 Blindfolded' '2017SWAR03' 'Dylan Swarts' '30446' '-1' 'single & average'
'4x4x4 Blindfolded' '2017LAWR04' 'Timothy Lawrance' '39375' '-1' 'single & average'
'4x4x4 Blindfolded' '2019PAUL10' 'Ehikhuemen Paul' '22153' '-1' 'single only'
'4x4x4 Blindfolded' '2015FAUG01' 'Marike Faught' '36369' '-1' 'single only'
'4x4x4 Blindfolded' '2015GROB02' 'Ruben Grobler' '39792' '-1' 'single only'
'4x4x4 Blindfolded' '2019LANG03' 'Heinrich de Lange' '47980' '-1' 'single only'
'4x4x4 Blindfolded' '2015SALA03' 'Taha Ben Salah' '52211' '-1' 'single only'
'5x5x5 Cube' '2018RUSH01' 'Daniel Rush' '5134' '5649' 'single & average'
'5x5x5 Cube' '2019SAMU06' 'Ayooluwa Samuel Dada' '5057' '5652' 'single & average'
'5x5x5 Blindfolded' '2015FAUG01' 'Marike Faught' '78600' '-1' 'single only'
'5x5x5 Blindfolded' '2017LAWR04' 'Timothy Lawrance' '79700' '-1' 'single only'
'5x5x5 Blindfolded' '2017SWAR03' 'Dylan Swarts' '88100' '-1' 'single only'
'5x5x5 Blindfolded' '2015SALA03' 'Taha Ben Salah' '106000' '-1' 'single only'
'6x6x6 Cube' '2018RUSH01' 'Daniel Rush' '9112' '-1' 'single & average'
'6x6x6 Cube' '2019SAMU06' 'Ayooluwa Samuel Dada' '9852' '10402' 'single & average'
'6x6x6 Cube' '2022FOUR01' 'Herman Fourie' '11214' '12037' 'single & average'
'6x6x6 Cube' '2015GROB02' 'Ruben Grobler' '11723' '12121' 'single & average'
'7x7x7 Cube' '2019SAMU06' 'Ayooluwa Samuel Dada' '15557' '-1' 'single & average'
'7x7x7 Cube' '2018RUSH01' 'Daniel Rush' '14272' '14698' 'single & average'
'7x7x7 Cube' '2015GROB02' 'Ruben Grobler' '17273' '18736' 'single & average'
'7x7x7 Cube' '2022FOUR01' 'Herman Fourie' '17838' '18260' 'average only'
'Clock' '2019RAGH04' 'Rafik Sarwat Naeem Ragheb' '446' '-1' 'single & average'
'Clock' '2019RAGH04' 'Rafik Eskandar' '446' '-1' 'single & average'
'Clock' '2015HARR01' 'Ryan Pin Harry' '537' '619' 'single & average'
'Megaminx' '2019LANG03' 'Heinrich de Lange' '3795' '4190' 'single & average'
'Megaminx' '2015BOUG02' 'Emna Boughizane' '4605' '5082' 'single & average'
'Megaminx' '2022DAVI30' 'Atobatele Oreoluwapo David' '4388' '4690' 'single only'
'Megaminx' '2018RUSH01' 'Daniel Rush' '4177' '5357' 'single only'
'Megaminx' '2019SAMU06' 'Ayooluwa Samuel Dada' '4390' '5440' 'single only'
'Pyraminx' '2020BELA01' 'Badr Ait Belaid' '246' '324' 'single & average'
'Pyraminx' '2015GROB02' 'Ruben Grobler' '258' '401' 'single & average'
'Pyraminx' '2015BOUS02' 'Moez Boussarsar' '239' '410' 'single & average'
'Pyraminx' '2013CRON01' 'Conor Cronin' '410' '528' 'single & average'
'Pyraminx' '2020ROOD02' 'Chase Lee Roodt' '268' '417' 'single only'
'Pyraminx' '2019ANTA02' 'Ali Antar' '276' '421' 'single only'
'Pyraminx' '2021GOOS01' 'Andre Johannes Goosen' '297' '455' 'single only'
'Pyraminx' '2022VIEI01' 'Adriano Vieira' '369' '481' 'single only'
'Pyraminx' '2016BLUM01' 'Cameron Blumenow' '322' '488' 'single only'
'Pyraminx' '2017SWAR03' 'Dylan Swarts' '383' '509' 'single only'
'Pyraminx' '2014PEAR02' 'Maverick Pearson' '353' '523' 'single only'
'Pyraminx' '2019WESS01' 'Callan Wesson' '425' '524' 'single only'
'Pyraminx' '2022OSBU01' 'Jesse Osburn' '331' '528' 'single only'
'Pyraminx' '2018RUSH01' 'Daniel Rush' '310' '570' 'single only'
'Pyraminx' '2015BOUS03' 'Aziz Boussarsar' '419' '578' 'single only'
'Pyraminx' '2017LAWR04' 'Timothy Lawrance' '408' '591' 'single only'
'Pyraminx' '2019COLL13' 'Samuel Collett' '415' '594' 'single only'
'Pyraminx' '2022MOOR15' 'Daniel Peter Charles Moore' '405' '595' 'single only'
'Pyraminx' '2019SAMU06' 'Ayooluwa Samuel Dada' '376' '625' 'single only'
'Pyraminx' '2015KERK03' 'Rayan Kerkeni' '400' '649' 'single only'
'Pyraminx' '2019BOTH02' 'Christiaan Botha' '371' '667' 'single only'
'Pyraminx' '2019RAGH04' 'Rafik Sarwat Naeem Ragheb' '425' '683' 'single only'
'Pyraminx' '2019RAGH04' 'Rafik Eskandar' '425' '683' 'single only'
'Pyraminx' '2019MUTH01' 'Jay Kuria Muthari' '362' '734' 'single only'
'Pyraminx' '2018ANAS01' 'Anass Doublal' '261' '741' 'single only'
'Pyraminx' '2014GRAY03' 'Brendan James Gray' '405' '812' 'single only'
'Pyraminx' '2022HAMM13' 'Ferielle Hammami' '354' '825' 'single only'
'Pyraminx' '2016HARI06' 'Shivaan Harichander' '381' '861' 'single only'
'Pyraminx' '2019DEYZ01' 'Walt Deyzel' '364' '870' 'single only'
'Pyraminx' '2022MOHA04' 'Belkacem Mohand' '386' '912' 'single only'
'Pyraminx' '2015RAMR01' 'Pranav Ramraj' '357' '968' 'single only'
'Pyraminx' '2019BADR01' 'Osman Badroodin' '366' '973' 'single only'
'Pyraminx' '2019HOOS01' 'Waseem Hoosain' '371' '982' 'single only'
'Pyraminx' '2016MOUT01' 'William Mouton' '394' '1017' 'single only'
'Pyraminx' '2022AUFR01' 'Eli Aufrichtig' '423' '1480' 'single only'
'Pyraminx' '2015BOSM03' 'Timothy Bosman' '425' '1724' 'single only'
'Skewb' '2016KALL01' 'Hassen Kallala' '228' '371' 'single & average'
'Skewb' '2015CHOK01' 'Mohamed Ben Driss Chokri' '239' '451' 'single & average'
'Skewb' '2014TIPT01' 'Jesse Tipton' '283' '529' 'single & average'
'Skewb' '2022FORD05' 'Tristan Ford' '353' '417' 'average only'
'Skewb' '2015GROB02' 'Ruben Grobler' '310' '451' 'average only'
'Skewb' '2022BLIG01' 'Estian Blignaut' '389' '457' 'average only'
'Skewb' '2022OLUW01' 'Adejuwon Adebusuyi Oluwemimo' '413' '459' 'average only'
'Skewb' '2015BOUS03' 'Aziz Boussarsar' '419' '491' 'average only'
'Skewb' '2015BOUS02' 'Moez Boussarsar' '424' '492' 'average only'
'Skewb' '2019ANTA02' 'Ali Antar' '282' '528' 'single only'
'Square-1' '2019RAGH04' 'Rafik Sarwat Naeem Ragheb' '695' '944' 'single & average'
'Square-1' '2019RAGH04' 'Rafik Eskandar' '695' '944' 'single & average'
'Square-1' '2019BADR01' 'Osman Badroodin' '843' '1013' 'single & average'
'Square-1' '2022OKOR01' 'David Okoro-Sokoh' '869' '1059' 'single & average'
'Square-1' '2018LANG07' 'Andreas de Lange' '861' '1547' 'single only'
'Square-1' '2016KALL01' 'Hassen Kallala' '888' '1626' 'single only'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment