Last active
August 29, 2015 13:57
-
-
Save glamp/9450319 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select | |
gameid | |
, s as seconds_remaining | |
into tmp_game_states | |
from (select distinct gameid from ncaa_basketball) b | |
, generate_series(0, 2400); | |
select | |
g.gameid | |
, g.seconds_remaining | |
, bb.away | |
, bb.home | |
, max(case when g.seconds_remaining = 2400 then 0 else bb.away_score end) as away_score | |
, max(case when g.seconds_remaining = 2400 then 0 else bb.home_score end) as home_score | |
from | |
tmp_game_states g | |
left join | |
ncaa_basketball bb | |
on g.seconds_remaining = bb.seconds_remaining | |
and g.gameid = bb.gameid | |
group by | |
g.gameid | |
, g.seconds_remaining | |
, bb.away | |
, bb.home | |
order by | |
g.gameid | |
, g.seconds_remaining desc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment