elsina Who made the most profit?
    Updated 2022-07-16
    with nfts_contract as (
    select address, project_name
    from polygon.core.dim_labels
    where project_name ilike '%nft%' or project_name ilike '%opensea%'
    ),
    txs as (
    select tx_hash as tx
    from polygon.core.fact_event_logs, nfts_contract
    where address = contract_address
    ),
    amount as (
    select to_address as addr, -sum(matic_value) as volume
    from polygon.core.fact_transactions, txs
    where tx_hash = tx
    group by 1

    union all

    select from_address as addr, sum(matic_value) as volume
    from polygon.core.fact_transactions, txs
    where tx_hash = tx
    group by 1
    )
    (
    select addr, volume
    from amount
    order by 2 desc
    limit 100
    )

    Run a query to Download Data