select
block_timestamp::date as day,
sum(gas_limit/pow(10,9)) as Fee_flow,
(sum(gas_limit/pow(10,9)) * avg(price_usd)) as Fee_in_usd,
avg(price_usd) as flow_price
from flow.core.fact_transactions inner join flow.core.fact_prices p
on timestamp::date = block_timestamp::date and hour(p.timestamp) = hour(block_timestamp)
where block_timestamp > CURRENT_DATE - 31
and token = 'Flow'
and tx_succeeded = 'TRUE'
group by day