Skip to content

Commit

Permalink
Introduce second layer of best-only aggregation via ROW_NUMBER
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorbg committed Dec 31, 2024
1 parent c3431aa commit f98cc3d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/auxiliary_data_computation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,17 @@ def self.compute_rank_tables
SELECT eventId, personId, countryId, continentId, min(#{field}) `value`
FROM #{concise_table_name}
GROUP BY personId, countryId, continentId, eventId
), best_table AS (
SELECT *, ROW_NUMBER() OVER (PARTITION BY eventId, personId ORDER BY value) AS really_best
FROM temp_table
)
SELECT
personId, eventId, `value`,
RANK() OVER(PARTITION BY eventId ORDER BY `value`) AS worldRank,
RANK() OVER(PARTITION BY eventId, continentId ORDER BY `value`) AS continentRank,
RANK() OVER(PARTITION BY eventId, countryId ORDER BY `value`) AS countryRank
FROM personal_best
FROM best_table
WHERE really_best = 1
ORDER BY eventId, `value`
SQL
end
Expand Down

0 comments on commit f98cc3d

Please sign in to comment.