Query editor
WITH date_filter AS (SELECTdate_trunc('week', CURRENT_DATE - INTERVAL '180' DAY) as start_date,date_trunc('week', CURRENT_DATE) as end_date),-- Simplified gifts processing without complex string operationsgifts_clean AS (SELECTa.collection_name,b.col_address as collection_address,max_supply,current_supply,price_usd,LOWER(a.collection_name) AS simple_nameFROM dune.rdmcd_team.gifts aleft join dune.rdmcd.result_gifts_collection_addresses b on a.collection_name = b.item_nameWHERE max_supply > 0 AND current_supply > 0),-- Simplified metadata processingnft_meta_clean AS (SELECTaddress,MAX_BY(name, adding_date) AS name,LOWER(MAX_BY(name, adding_date)) AS simple_nameFROM ton.nft_metadatawhere address in (SELECT distinct col_address FROM dune.rdmcd.result_gifts_collection_addresses)GROUP BY address),-- Get only relevant sales data with filters applied earlyrelevant_sales AS (SELECTNE.collection_address,gc.collection_name,gc.max_supply,gc.current_supply,gc.price_usd as mint_price_usd,DATE_TRUNC('week', NE.block_date) AS week_start,NE.sale_price * P.price_usd AS sale_price_usdFROM ton.nft_events NECROSS JOIN date_filter dfINNER JOIN ton.prices_daily PON P.timestamp = NE.block_dateAND P.token_address = '0:0000000000000000000000000000000000000000000000000000000000000000'left join gifts_clean gcon NE.collection_address = gc.collection_addressWHERE NE.type = 'sale'AND NE.payment_asset = 'TON'AND NE.block_date >= df.start_dateAND NE.block_date <= df.end_dateAND NE.sale_price > 0AND gc.collection_name IS NOT NULL -- Only include collections we have gift data for),-- Calculate weekly statsweekly_stats AS (SELECTcollection_address,