adambalaPolygon NFT-- top 20 users with most profit in ETH
    Updated 2022-07-17
    with
    tx_sell as (
    select
    sum(AMOUNT) as eth_sold,from_ADDRESS
    from flipside_prod_db.polygon.udm_events
    where
    CONTRACT_ADDRESS='0x7ceb23fd6bc0add59e62ac25578270cff1b9f619' and
    EVENT_TYPE='erc20_transfer' and ORIGIN_ADDRESS='0x9b814233894cd227f561b78cc65891aa55c62ad2' and EVENT_NAME='transfer' and
    ORIGIN_FUNCTION_SIGNATURE ='0xbbbfa60c'
    group by 2 ),

    tx_buy as (
    select sum(AMOUNT) as eth_bought ,TO_ADDRESS
    from flipside_prod_db.polygon.udm_events
    where
    CONTRACT_ADDRESS='0x7ceb23fd6bc0add59e62ac25578270cff1b9f619' and
    EVENT_TYPE='erc20_transfer' and ORIGIN_ADDRESS='0x9b814233894cd227f561b78cc65891aa55c62ad2' and EVENT_NAME='transfer' and
    ORIGIN_FUNCTION_SIGNATURE ='0xbbbfa60c'
    group by 2)

    select
    TO_ADDRESS ,eth_sold -eth_bought as net_profit
    from
    tx_sell inner join tx_buy
    on from_ADDRESS=TO_ADDRESS

    where net_profit > 0
    order by net_profit desc limit 20


    Run a query to Download Data