Skip to content

Instantly share code, notes, and snippets.

@knewter
Created May 4, 2013 16:04
Show Gist options
  • Save knewter/5517927 to your computer and use it in GitHub Desktop.
Save knewter/5517927 to your computer and use it in GitHub Desktop.
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, 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 > (1367153251 - (120 * 300))
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