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 = {{nft_contract}}AND to NOT IN ({{staking_contract}}))WHERErn = 1GROUP BYto) AS holderLEFT JOIN (SELECT"from",COUNT(tokenId) AS token_stakedFROM erc721_ethereum.evt_TransferWHEREcontract_address = {{nft_contract}}AND to NOT IN({{staking_contract}})GROUP BY"from") AS stakedON staked."from" = holder.toLEFT JOIN (SELECTto,COUNT(tokenId) AS token_unstakedFROM erc721_ethereum.evt_TransferWHEREcontract_address = {{nft_contract}}AND "from" IN ({{staking_contract}})GROUP BYto) AS unstakedON unstaked.to = holder.toORDER BY token_count DESC), recap AS (SELECTb.*,DATE_DIFF('day', l.last_transaction_date, current_date) AS inactivity_days,DATE_DIFF('month', l.last_transaction_date, current_date) AS inactivity_months,l.last_transaction_date