Created
March 21, 2022 13:33
-
-
Save peacing/50bbc3d4cae62948f188452a1feeb24e 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
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