Query editor
WITH balances as (SELECTholder.to,holder.token_count,COALESCE(staked.token_staked, 0) AS token_staked,COALESCE(unstaked.token_unstaked, 0) AS token_unstaked,COALESCE(staked.token_staked, 0) - COALESCE(unstaked.token_unstaked, 0) as token_in_staking,(holder.token_count - COALESCE(staked.token_staked, 0) + COALESCE(unstaked.token_unstaked, 0)) as token_in_wallet,holder.token_listFROM (SELECTto,COUNT(DISTINCT tokenId) AS token_count,ARRAY_AGG(tokenId) AS token_listFROM (SELECTtokenId,to,ROW_NUMBER() OVER (PARTITION BY tokenId ORDER BY evt_block_number DESC, evt_index DESC) AS rnFROM erc721_ethereum.evt_TransferWHEREcontract_address = 0xc9d198089d6c31d0ca5cc5b92c97a57a97bbfde2AND to <> 0xc9d198089d6c31d0ca5cc5b92c97a57a97bbfde2)WHERErn = 1GROUP BYto) AS holderLEFT JOIN (SELECT"from",COUNT(tokenId) AS token_stakedFROM erc721_ethereum.evt_TransferWHEREcontract_address = 0xc9d198089d6c31d0ca5cc5b92c97a57a97bbfde2AND to = 0xc9d198089d6c31d0ca5cc5b92c97a57a97bbfde2GROUP BY"from") AS stakedON staked."from" = holder.toLEFT JOIN (SELECTto,COUNT(tokenId) AS token_unstakedFROM erc721_ethereum.evt_TransferWHEREcontract_address = 0xc9d198089d6c31d0ca5cc5b92c97a57a97bbfde2AND "from" = 0xc9d198089d6c31d0ca5cc5b92c97a57a97bbfde2GROUP BYto) AS unstakedON unstaked.to = holder.toORDER BY token_count DESC), last_transaction_date AS (SELECT"from" AS address,MAX(DATE_TRUNC('day', block_time)) AS last_transaction_dateFROM ethereum.transactions