with tab1 as (
select
buyer as buy,
sum(price)
from flow.core.fact_nft_sales
group by 1
Order by 2 DESC
limit 500
)
, tab2 as (
select
tx_id
from flow.core.fact_transactions
where proposer in (select buy from tab1)
)
select
date_trunc('day', block_timestamp),
event_type,
count(*)
from flow.core.fact_events
where tx_succeeded = 'TRUE'
and tx_id in (select * from tab2)
group by 1, 2