with vol as (
select
date_trunc('day',block_timestamp) AS dayz,
sum(TO_AMOUNT_MIN_USD) as volsum
from thorchain.swaps
group by 1
order by 1 desc
),
RUNEp as (
SELECT date_trunc('day',block_timestamp) AS day,
avg(RUNE_USD) as runep FROM thorchain.prices group by 1
ORDER BY day DESC
),
lastly as (
select day, volsum,
runep
from RUNEp
left join
vol
on vol.dayz = RUNEp.DAY
where dayz is not NULL
and runep is not null
order by dayz desc)
select DAY, VOLSUM, RUNEP, VOLSUM/RUNEP from lastly
order by 1 desc