Ranking NHL Players and Finding Who They Play Like on AlloyDB
As a hobby, I collect NHL data and build sports analytics on top of it. A set of jobs loads every game’s box score each night, and I use the results to look at players, matchups and betting lines. This post shows how to determine how a player ranks against the rest of the league, and which players he plays like.
A raw number doesn’t tell you much on its own. Auston Matthews has 3.77 points per 60 minutes this season. Is that good? Probably, but I couldn’t tell you whether it’s top 10 or top 50 without opening a spreadsheet. I wanted every player card to answer that on its own.
The database behind all of this is AlloyDB Express, so that’s where the ranking lives. I picked it because it’s PostgreSQL 18 underneath, so my schema and SQL came over unchanged, and an instance is ready in seconds. pgvector is already installed, which mattered for the second half of this post. It also pauses itself when idle, and there’s a free tier, which suits a hobby project that sits quiet most of the day.
The Data
Two tables matter here:
skater_game_stats: one row per skater per game, with goals, assists, shots, hits, blocks, takeaways, giveaways, power-play goals and time on ice.goalie_game_stats: one row per goalie per game, with shots and goals against at even strength and on the penalty kill, saves, ice time and the decision.
The 2026–27 regular season is 384 games old as I write this. That’s 13,824 skater rows across 789 skaters, small enough that I currently didn’t need to think about performance.
Ranking in SQL
Before writing any SQL, I set three rules:
Rates, not totals. A player who missed six games shouldn’t rank lower for it. Skater stats are per 60 minutes of ice time, so the rank reflects how a player plays, not how much.
Rank within a position. Defencemen and forwards don’t produce the same numbers, so I rank them separately. Goalies get their own set of stats.
A minimum sample. A call-up with 40 minutes and two goals would top the goals/60 list. Skaters need 200 minutes to be ranked and goalies need five appearances.
The query itself has two steps.
Step 1: one row per stat. After totalling the season, each player has one row with a column per stat. Ranking works better the other way around, with one row per player per stat, so that a single query can rank every stat. A LATERAL VALUES list does that reshaping. Each line produces one row: a sort order, the stat’s name, its value, and whether a higher number is better.
CROSS JOIN LATERAL (VALUES
(1, 'Points/60', (t.g + t.a) * 3600.0 / t.toi, true),
(2, 'Goals/60', t.g * 3600.0 / t.toi, true),
...
(9, 'Giveaways/60', t.giveaways * 3600.0 / t.toi, false),
(10, 'TOI/GP (min)', t.toi / 60.0 / t.games, true)
) AS v(sort_order, stat, value, higher_is_better)
t.toi is ice time in seconds, so * 3600.0 / t.toi turns a count into a rate per 60 minutes. After this step, Matthews’ one row has become ten:
| player | stat | value | higher_is_better |
|---|---|---|---|
| Auston Matthews | Points/60 | 3.77 | true |
| Auston Matthews | Goals/60 | 1.55 | true |
| … | … | … | … |
| Auston Matthews | Giveaways/60 | 2.44 | false |
Step 2: rank each stat. Fewer giveaways is better, so ranking every stat highest-first would get that one backwards. I add a column called good that flips the sign when lower is better: CASE WHEN higher_is_better THEN value ELSE -value END. Now bigger is better for every stat, and three window functions do the rest:
SELECT player_id, player, pos_group, stat, round(value, 2) AS value,
rank() OVER (PARTITION BY pos_group, stat ORDER BY good DESC) AS league_rank,
count(*) OVER (PARTITION BY pos_group, stat) AS ranked,
floor(100 * percent_rank()
OVER (PARTITION BY pos_group, stat ORDER BY good))::int AS percentile
FROM scored;
PARTITION BY pos_group, stat splits the rows into separate lists, such as “Points/60 among forwards”, and each function works inside its own list:
rank()is the player’s place in the list, so 1 is best.count(*)is how many players are in the list.percent_rank()is the share of the list he’s ahead of, from 0 to 1. Times 100, that’s the percentile. Matthews’ 97 in points/60 means he’s ahead of 97% of the other forwards.
I made these views rather than tables. At a season of box scores the query is cheap, and a view means a rank is never older than last night’s load.
Creating the Views
The views live in their own league schema, separate from the tables the nightly jobs write to. I connect through the AlloyDB Auth Proxy and run the file:
$ psql "$ALLOYDB_NHL" -f league-ranks.sql
Then a player’s ranks are one query away:
$ psql "$ALLOYDB_NHL" -c "SELECT stat, value, league_rank, ranked, percentile
FROM league.skater_ranks WHERE player = 'Auston Matthews' ORDER BY sort_order"
stat | value | league_rank | ranked | percentile
--------------+-------+-------------+--------+------------
Points/60 | 3.77 | 11 | 350 | 97
Goals/60 | 1.55 | 31 | 350 | 91
Assists/60 | 2.22 | 28 | 350 | 92
Shots/60 | 9.08 | 34 | 350 | 90
PP goals/60 | 0.55 | 36 | 350 | 89
Hits/60 | 2.88 | 216 | 350 | 38
Blocks/60 | 2.66 | 70 | 350 | 80
Takeaways/60 | 1.44 | 26 | 350 | 92
Giveaways/60 | 2.44 | 109 | 350 | 69
TOI/GP (min) | 20.83 | 15 | 350 | 95
That answers my original question. Matthews is 11th of 350 forwards in points per 60, which puts him in the 97th percentile.
Plays Like
Once every player has a percentile for each stat, those percentiles describe the player. Scaled to 0–1 and kept in stat order, Matthews’ ten percentiles become a ten-dimension vector. Two players whose vectors sit close together have the same strengths and weaknesses at a similar level.
AlloyDB Express ships with Google’s build of pgvector (0.8.7.google-1 on my instance), so this is one more view on top of the ranks:
CREATE OR REPLACE VIEW league.player_vectors AS
SELECT player_id, player, pos_group,
array_agg(percentile / 100.0 ORDER BY sort_order)::vector AS profile
FROM league.skater_ranks
GROUP BY player_id, player, pos_group;
The real view also unions in the goalies from league.goalie_ranks, with eight dimensions instead of ten. Finding the closest players is an ORDER BY on distance:
SELECT o.player
FROM league.player_vectors me
JOIN league.player_vectors o
ON o.pos_group = me.pos_group AND o.player_id <> me.player_id
WHERE me.player = 'Cale Makar'
ORDER BY me.profile <-> o.profile
LIMIT 3;
I use Euclidean distance (<->) rather than cosine. Cosine only compares the direction of two vectors, so a star and a depth player with the same strengths would look alike. Euclidean distance also accounts for level. With a few hundred players per position, I didn’t add a vector index; an exact scan is cheap at this size. When that changes, AlloyDB’s ScaNN index is the next step. I’ve already checked that it builds on Express and that the planner uses it. It becomes worth it once I move to one vector per player per game across several seasons.
The Player Card
Each player gets a card with his season line in the header and eight ranked stats under it, in two columns. The skater view ranks ten, but eight is what fits without the card turning into a table. Every stat shows its value, his rank, and a percentile bar. A tick at the halfway point marks the league median, and bars under it are faded so below-average stats stand out at a glance. A Plays like row at the bottom lists his three nearest players.

Figure 1: Auston Matthews against 350 forwards. Top 10% in points, goals and assists per 60, below the median in hits.
The shape of the bars says as much as any single number. Cale Makar is first among 196 defencemen in assists per 60 and second in points per 60. He’s also in the 5th percentile for hits and the 13th for blocks. That’s what a defenceman who has the puck most of the time looks like. His closest match is Quinn Hughes, followed by teammate Devon Toews.

Figure 2: Cale Makar against 196 defencemen.
Goalies use a different set of stats, including goals saved above average (GSAA): how many fewer goals he allowed than a league-average goalie would have on the same shots. Jesper Wallstedt leads the league in GSAA at +16.8, and in wins and starts. His penalty-kill save percentage is closer to average, at 27th of 65. Mackenzie Blackwood is his nearest match.

Figure 3: Jesper Wallstedt against 65 goalies with at least five appearances.
Final Thoughts
What I like most is that everything lives in one database. The nightly box scores, the ranks and the vectors all sit in AlloyDB, so there’s no separate vector store to run or keep in sync. Window functions do the ranking, pgvector does the matching, and both run next to the ingested data without any tuning on my part.
Express also leaves room to grow. It caps storage at 20 GB, far more than a season of box scores needs. When I outgrow it, it upgrades in place to a full AlloyDB cluster with one command, and the connection string stays the same.
The main limitation is the sample, not the database. Twenty-odd games is not much, and a few hot nights can move a player a long way up or down the list. The ranks are a better guide in March than in November.
Next, I want these ranks available to Claude through an MCP server, so I can ask how a player stacks up in the same conversation where I’m looking at his props.