Skip to content

Example Queries

Matthew Pope edited this page Jan 2, 2025 · 4 revisions

Here are a set of queries that can pull interesting data.

Triple Doubles

Here is a simple way to pull triple doubles for a player

SELECTSUM(td3) FROM player_game_log LEFT JOIN player ONplayer.player_id=player_game_log.player_idWHEREplayer.player_name='Russell Westbrook';

Shot Distance Relative To Seconds Remaining In A Period

select
((minutes_remaining *60) + seconds_remaining) as total_time_remaining,
shot_distance
from shot_chart_detail scd
left join player onplayer.player_id=scd.player_idwhereplayer.player_name='LeBron James'andscd.shot_made_flag= false and period <=4order by total_time_remaining desc;

Shot Distance Relative To Seconds Remaining In A Game

This is similar to the query above, but we introduce a formula based on the period of the shot to calculate the seconds into the game that the shot was made:

minutes_in_period = 12 * 60
(minutes_in_period * (5 - period)) - (minutes_in_period - ((minutes_remaining * 60) + seconds_remaining))

With that in mind, here is the query:

select
(12*60* (5- period)) - ((12*60) - ((minutes_remaining *60) + seconds_remaining)) as total_time_remaining,
shot_distance
from shot_chart_detail scd
left join player onplayer.player_id=scd.player_idwhereplayer.player_name='Stephen Curry'andscd.shot_made_flag= true and period <=4order by total_time_remaining desc;

Counting Misses

Want to find the players with the most misses?

SELECTp.player_name, count(*) AS total FROM play_by_play LEFT JOIN player p onp.player_id= player1_id WHERE home_description LIKE'MISS%'OR visitor_description like'MISS%'GROUP BYp.player_nameORDER BY total DESC;

How about by period?

SELECTp.player_name, count(*) AS total, period
FROM play_by_play
LEFT JOIN player p onp.player_id= player1_id
WHERE
home_description LIKE'MISS%'OR visitor_description like'MISS%'GROUP BYp.player_name, period
ORDER BY total DESC;

Unique Stat Lines

SELECTCOUNT(*) FROM (
SELECT DISTINCT fgm, fga, fgm, fga, fg3m, fg3a, ftm, fta, oreb, dreb, stl, bl
FROM player_game_log
) AS stat_line

Clone this wiki locally