Skip to content

Instantly share code, notes, and snippets.

@AlphaSheep
Last active July 8, 2024 07:50
Show Gist options
  • Save AlphaSheep/5412a0073fda4fd85c67acae17bb8b3b to your computer and use it in GitHub Desktop.
Save AlphaSheep/5412a0073fda4fd85c67acae17bb8b3b to your computer and use it in GitHub Desktop.
Historical WCA Ranking Query
drop table if exists y_comp_dates;
create table y_comp_dates as
select
id as competitionId,
year * 10000 + endMonth * 100 + endDay as endDate
from
Competitions;
drop table if exists y_results;
create table y_results as
select
competitionId,
eventId,
roundTypeId,
personId,
personName,
pos,
best,
average
from
Results
where
eventId='222'
and average <= 150
and average > 0;
drop table if exists y_result_dates;
create table y_result_dates as
select
y_results.competitionId as competitionId,
eventId,
roundTypeId,
personId,
personName,
pos,
best,
average,
endDate
from
y_results
left join y_comp_dates on y_results.competitionId = y_comp_dates.competitionId
where
endDate <= 20230427;
drop table if exists y_average_rankings;
create table y_average_rankings as
select
rank() over (order by min(average)) as num,
personId,
personName,
min(average) as average
from
y_result_dates
group by
personId,
personName;
select *
from y_average_rankings
order by num desc;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment