keshanSushibar 3
    Updated 2022-03-02
    with top_users as (select user_address from ethereum.erc20_balances
    where contract_address = lower('0x8798249c2E607446EfB7Ad49eC89dD1865Ff4272') and date_trunc('day', balance_date) = date_trunc('day', CURRENT_DATE) - 1
    group by 1
    order by sum(balance) DESC
    limit 100)

    select date_trunc('day', block_timestamp) as date, to_address as user, to_address_name as name,
    sum(case when from_address = '0x0000000000000000000000000000000000000000' then amount else 0 end) as sushibar,
    sum(case when from_label_type = 'dex' or from_label_type = 'cex' then amount else 0 end) as market,
    sum(amount) as amount
    from ethereum.udm_events where contract_address = lower('0x8798249c2E607446EfB7Ad49eC89dD1865Ff4272')
    and to_address in (select user_address from top_users)
    group by date, user, name
    Run a query to Download Data