forked from Jman4190/nba-sql
-
Notifications
You must be signed in to change notification settings - Fork 20
Example Queries
Matthew Pope edited this page Sep 5, 2021
·
1 revision
Here are a set of queries that can pull interesting data.
Here is a simple way to pull triple doubles for a player
SELECT SUM(td3)
FROM player_game_log
LEFT JOIN player ON player.player_id = player_game_log.player_id
WHERE player.player_name = 'Russell Westbrook';
select
((minutes_remaining * 60) + seconds_remaining) as total_time_remaining,
shot_distance
from shot_chart_detail scd
left join player on player.player_id = scd.player_id
where
player.player_name = 'LeBron James' and
scd.shot_made_flag = false and
period <= 4
order by total_time_remaining desc;
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 on player.player_id = scd.player_id
where
player.player_name = 'Stephen Curry' and
scd.shot_made_flag = true and
period <= 4
order by total_time_remaining desc;