with main1 as (
select
tx_receiver as contract,
sum(gas_used/1e12) as total_gas,
count(TXN_HASH) as tx_count,
(total_gas/tx_count) as avg_gas_used
from flipside_prod_db.mdao_near.transactions
where BLOCK_TIMESTAMP > CURRENT_DATE - 7
group by 1
order by avg_gas_used desc
)
select
contract,
avg_gas_used
from main1
where tx_count > 1000
order by 2 asc
limit 10