Query editor
-- goal is to find the first 100 buyers of alpaca token and their current balanceWITH transferEvents AS(SELECTcontract_address,evt_block_number,evt_block_time,evt_index,evt_tx_hash,"from","to","value"FROM erc20_{{blockchain}}.evt_transferWHEREevt_block_number >={{initial_block_number}}ANDcontract_address={{token_address}}),-- this cte is to analyze the first time transfer that was made to the walletsfirstTransfer AS(SELECT"to" AS address,MIN(evt_block_time) AS first_transfer_timeFROMtransferEventsGROUP BY "to"),-- this cte is to find the initial balance of the wallet that received firstinitialBalances AS(SELECTt."to" AS address,SUM(CAST(t.value AS INT256)) AS initial_balance,f.first_transfer_time AS initial_buy_timeFROMtransferEvents tJOIN firstTransfer f ON t."to" = f.address AND t.evt_block_time = f.first_transfer_timeGROUP BY t."to", f.first_transfer_time),-- to find currentcurrentTransfers AS((SELECT"to" AS address,SUM(CAST(value AS INT256)) AS balance --to find the positive balance of the wallet(incoming transfer)FROM transferEventsGROUP BY "to")UNION ALL (SELECT"from" AS address,- SUM(CAST(value AS INT256)) AS balance --negative balance of the wallets(sell out) excluding the mint walletFROM transferEventsWHERE "from" != 0x000000000000000000000000000000000000GROUP BY "from")),-- current balance of the wallets we are analyzingcurrentBalances AS(SELECT