Query editor
WITHlast_ethereum AS (SELECTlatest."tokenId",transfer."evt_index",REPLACE(TRY_CAST(transfer."to" AS VARCHAR), '\', '0') AS current_owner,transfer."from" AS previous_owner,transfer."evt_tx_hash",transfer."evt_block_time",transfer."evt_block_number"FROM(SELECT"tokenId",MAX("evt_block_number") AS latest_transfer_block_numberFROMerc721_ethereum.evt_TransferWHEREcontract_address = 0x5816c699f66592179A227C5C2FF8486243962951GROUP BY"tokenId") AS latestJOIN erc721_ethereum.evt_Transfer AS transfer ON latest."tokenId" = transfer."tokenId"AND latest."latest_transfer_block_number" = transfer."evt_block_number"),combined_owners AS (SELECTco.current_owner,COUNT(co.tokenId) AS land_countFROM (SELECTcurrent_owner,tokenIdFROMlast_ethereum) AS coLEFT JOIN labels.contracts AS cON c.blockchain = 'ethereum'AND c.address = CAST(co.current_owner AS varbinary)GROUP BYco.current_owner)SELECTconcat('<a href="https://debank.com/profile/', cast(co.current_owner AS varchar), '" target="_blank">', cast(co.current_owner AS varchar), '</a>') AS owner,CASEWHEN LOWER(c.name) LIKE '%gnosis%' THEN 'multisig'ELSE 'wallet'END AS address_type,array_agg(DISTINCT all_labels.name) AS labels,SUM(co.land_count) AS Treehoue_Squirrel_CouncilFROMcombined_owners AS coLEFT JOIN labels.contracts AS cON c.blockchain = 'ethereum'AND c.address = CAST(co.current_owner AS varbinary)LEFT JOIN labels.addresses AS all_labelsON all_labels.blockchain = 'ethereum'AND all_labels.address = CAST(co.current_owner AS varbinary)AND all_labels.label_type = 'identifier'AND all_labels.model_name != 'contracts'