Skip to content

Instantly share code, notes, and snippets.

@peacing
Created March 21, 2022 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peacing/50bbc3d4cae62948f188452a1feeb24e to your computer and use it in GitHub Desktop.
Save peacing/50bbc3d4cae62948f188452a1feeb24e to your computer and use it in GitHub Desktop.
with begin as
(select currency,
max(price) as price
from crypto_prices_delta
where date_key = {{date_key | sqlsafe}}
and datetime =
(select min(datetime)
from crypto_prices_delta
where date_key = {{date_key | sqlsafe}})
group by currency), end as
(select currency,
max(price) as price
from crypto_prices_delta
where date_key = {{date_key | sqlsafe}}
and datetime =
(select max(datetime)
from crypto_prices_delta
where date_key = {{date_key | sqlsafe}})
group by currency)
select begin.currency,
end.price as end_price,
begin.price as begin_price,
round((end.price - begin.price) / begin.price, 4) *100 as pct_change
from begin,
end
where begin.currency = end.currency
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment