Query editor
with token_balances as (select -- tokens sold-sum(cast(value as double) / 1e18) as amount, "from" as addressfrom erc20_base.evt_transfer awhere a.contract_address = 0xAC1Bd2486aAf3B5C0fc3Fd868558b082a531B2B4group by 2union allselect -- tokens boughtsum(cast(value as double) / 1e18) as amount, a.to as addressfrom erc20_base.evt_transfer awhere a.contract_address = 0xAC1Bd2486aAf3B5C0fc3Fd868558b082a531B2B4group by 2),token_holders as (selectaddress, sum(amount) as balancefrom token_balancesgroup by 1),token_trades as (selectt.tx_from, t.token_bought_address, t.token_sold_address, t.amount_usd, casewhen t.token_bought_address = 0xAC1Bd2486aAf3B5C0fc3Fd868558b082a531B2B4 then t.token_bought_amountelse 0end as token_bought_amount, casewhen t.token_sold_address = 0xAC1Bd2486aAf3B5C0fc3Fd868558b082a531B2B4 then t.token_sold_amountelse 0end as token_sold_amount, t.block_time, h.balancefrom dex.trades tinner join token_holders h on t.tx_from = h.addresswhere (t.token_sold_address = 0xAC1Bd2486aAf3B5C0fc3Fd868558b082a531B2B4 or t.token_bought_address = 0xAC1Bd2486aAf3B5C0fc3Fd868558b082a531B2B4)and h.balance>=100000),token_trading_volumes as (select tx_from, amount_token, amount_usd,direction, h.balance from (selecttx_from, count(*) as number_trades, sum(token_bought_amount) as amount_token, sum(amount_usd) as amount_usd, max(balance) as balance, 'buy' as directionfrom token_tradeswhere token_bought_address = 0xAC1Bd2486aAf3B5C0fc3Fd868558b082a531B2B4group by 1)