Query editor
WITH base AS (SELECTblock_time,date_trunc('day', block_time) AS day,nft_item_address,tx_hash,prev_owner AS seller,owner_address AS buyer,CAST(sale_price AS double)/1e9 AS price_tonFROM ton.nft_eventsWHERE type = 'sale'AND collection_address = '0:0E41DC1DC3C9067ED24248580E12B3359818D83DEE0304FABCF80845EAFAFDB2'AND sale_price IS NOT NULLAND sale_price > 0),daily AS (SELECTday,approx_percentile(price_ton, 0.50) AS median_price_tonFROM baseGROUP BY 1),daily_ma AS (SELECTday,AVG(median_price_ton) OVER (ORDER BY dayROWS BETWEEN 29 PRECEDING AND CURRENT ROW) AS ma30_median_tonFROM daily),meta AS (SELECTaddress AS nft_item_address,name AS nft_name,regexp_extract(COALESCE(name, ''), '([+]?[0-9]{6,20})', 1) AS phone_number,ROW_NUMBER() OVER (PARTITION BY address ORDER BY address) AS rnFROM ton.nft_metadata),stats AS (SELECTapprox_percentile(price_ton, 0.01) AS p01,approx_percentile(price_ton, 0.99) AS p99FROM base)SELECTb.block_time,b.price_ton,m.phone_number,m.nft_name,b.nft_item_address,b.tx_hash,b.buyer,b.seller,d.ma30_median_ton,b.price_ton / NULLIF(d.ma30_median_ton, 0) AS premium_x,CASE