Query editor
SELECTholder.to,holder.token_count,COALESCE(staked.token_staked, 0) AS token_staked,/*(holder.token_count - COALESCE(staked.token_staked, 0) + COALESCE(unstaked.token_unstaked, 0)) AS token_in_wallet,*/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 = {{contract_address}}AND to <> {{staking_contract}})WHERErn = 1GROUP BYto) AS holderLEFT JOIN (SELECT"from",COUNT(tokenId) AS token_stakedFROM erc721_ethereum.evt_TransferWHEREcontract_address = {{contract_address}}AND to = {{staking_contract}}GROUP BY"from") AS stakedON staked."from" = holder.toLEFT JOIN (SELECTto,COUNT(tokenId) AS token_unstakedFROM erc721_ethereum.evt_TransferWHEREcontract_address = {{contract_address}}AND "from" = {{staking_contract}}GROUP BYto) AS unstakedON unstaked.to = holder.toORDER BY token_count DESC