Last active
December 17, 2015 00:00
-
-
Save knewter/5518120 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 to_timestamp(start_time * 300) start_time_tz, to_timestamp((start_time + 1) * 300) end_time_tz, sum(amount) as volume, min(price) as low, max(price) as high, coalesce(lag(max(last_price)) over (order by start_time), max(first_price)) as first, max(last_price) as last | |
from ( | |
select date/300 as start_time, amount, price, first_value(price) over w as first_price, last_value(price) over w as last_price | |
from trades | |
where date/300 >= ((1367153251/300) - 120) | |
window w as (partition by date/300 order by date rows between unbounded preceding and unbounded following) | |
) s | |
group by start_time | |
order by start_time desc; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment