Query editor
--- query_4898824: #sonieum-newsalewith response as (SELECT http_get('https://api.coingecko.com/api/v3/simple/price?ids=astar,ethereum&vs_currencies=usd') AS pricesFROM (SELECT 1 LIMIT 1)),token_prices AS (-- SELECT'ETH' AS currency, cast(JSON_EXTRACT_SCALAR(prices, '$.ethereum.usd') as double) AS token_price-- FROM responseSELECT'ETH' AS currency,token_pricefrom (select price * 1.0 AS token_pricefrom prices.usd_latest where symbol = 'WETH'and blockchain = 'base')UNION ALL-- SELECT'WETH' AS currency, cast(JSON_EXTRACT_SCALAR(prices, '$.ethereum.usd') as double) AS token_price-- FROM responseSELECT'WETH' AS currency,token_pricefrom (select price * 1.0 AS token_pricefrom prices.usd_latest where symbol = 'WETH'and blockchain = 'base')UNION ALLSELECT 'ASTR' AS currency, cast(JSON_EXTRACT_SCALAR(prices, '$.astar.usd') as double) AS token_priceFROM responseUNION ALLSELECT 'USDC' AS currency, 1 as token_priceFROM (SELECT 1 LIMIT 1)),by_currency as (selecttokenName,symbol,count(distinct buyer) as unique_buyers,sum(quantityBought) as num_sales,round(avg(totalPricePaid),3) as avg_price,round(max(totalPricePaid),3) as max_price,round(sum(quantityBought * totalPricePaid),3) as volume,currency,assetContractfrom query_4898824group by currency, tokenName, symbol, assetContract)selectCONCAT('<a href="https://www.fractalvisions.io/collections/', cast(assetContract as varchar), '/collection" target="_blank">🔗 ', tokenName, '</a>') as collectionName,sum(c.unique_buyers) as uniqueBuyers,sum(c.num_sales) as totalSales,sum(case c.currency when 'ETH' then c.num_sales when 'WETH' then c.num_sales else 0 end) as ethSales,sum(case c.currency when 'ASTR' then c.num_sales else 0 end) as astarSales,sum(case c.currency when 'USDC' then c.num_sales else 0 end) as usdcSales,round(avg(c.avg_price * t.token_price),2) as avgPrice,round(max(c.max_price* t.token_price),2) as maxPrice,round(sum(c.volume * t.token_price),2) as totalVolume,tokenName as collection,symbol