Query editor
with json_table AS (selectdate_trunc('day', evt_block_time) as date,distribution as parsed_jsonfrom merkl_{{chain}}.DistributionCreator_evt_NewDistribution),dates as (SELECT *FROM UNNEST(sequence(date('2023-02-20'), date(NOW()))) as s(dt)),-- group by dates and sum the $ value of rewardTokens so we have the $ sent to be distributed by dayplain_table as (selectdate,json_extract_scalar(parsed_json, '$.rewardToken') AS rewardToken,json_extract_scalar(parsed_json, '$.amount') AS amountFROM json_table),-- trying to get prices using prices_usd.latestprices.usd_latest-- not workingtable_w_prices as (selectdate,rewardToken,(cast(amount as double) / 1e18) as amount,casewhen rewardToken in (cast(0x31429d1856aD1377A8A0079410B297e1a9e214c2 as varchar), --ethereumcast(0x900F717EA076E1E7a484ad9DD2dB81CEEc60eBF1 as varchar), --polygoncast(0x58441E37255b09F9f545e9Dc957F1C41658ff665 as varchar), --optimismcast(0x656B80B667a46869144047E6e6C0000C81610253 as varchar)) --arbitrumthen (select ANGLE_price from query_2031740 where ANGLE_price > 0 order by week desc limit 1)else (select price from prices.usd where blockchain = '{{chain}}' and contract_address = from_hex(substring(rewardToken, 3)) and minute = date)end as pricefrom plain_table),-- "explode" this with the whole datestable_with_dates as (SELECTdates.dt as dates,coalesce((cast (amount as double))*price, 0) AS "$amount"FROM datesLEFT JOIN table_w_prices ON dates.dt = table_w_prices.dateORDER BY dates desc),-- then make it cumulativetable_cumulative as (selectdates,sum("$amount") over (order by dates) as cumulative_sumfrom table_with_dates)select * from table_cumulativewhere cumulative_sum > 10