with fees as (
select
block_timestamp::date as date
,tx_id
,fee
from osmosis.core.fact_transactions
where TX_STATUS='SUCCEEDED'
and fee !='0uosmo'
and fee like '%uosmo%'
)
select a.date,
b.msg_type,
count(a.tx_id) as num_tx,
sum(to_number(replace(a.fee,'uosmo',''))/pow(10,6)) as fees,
avg(fees) OVER (ORDER BY date) AS daily_avg_fee
from fees a join osmosis.core.fact_msgs b on a.tx_id = b.tx_id
where a.date >= CURRENT_DATE-30
group by 1, 2
order by 1