Query editor
withdata as (select *,casewhen vesting_duration/86400 = 0 then 'instant'when vesting_duration/86400 <= 3 then '1-3'when vesting_duration/86400 <= 7 then '4-7'when vesting_duration/86400 <= 14 then '8-14'when vesting_duration/86400 <= 28 then '15-28'when vesting_duration/86400 <= 60 then '29-60'when vesting_duration/86400 <= 90 then '61-90'when vesting_duration/86400 <= 180 then '91-180'when vesting_duration/86400 <= 270 then '181-270'else '270+'end as vesting_bucketfrom query_2280760 -- arbunion allselect *,casewhen vesting_duration/86400 = 0 then 'instant'when vesting_duration/86400 <= 3 then '1-3'when vesting_duration/86400 <= 7 then '4-7'when vesting_duration/86400 <= 14 then '8-14'when vesting_duration/86400 <= 28 then '15-28'when vesting_duration/86400 <= 60 then '29-60'when vesting_duration/86400 <= 90 then '61-90'when vesting_duration/86400 <= 180 then '91-180'when vesting_duration/86400 <= 270 then '181-270'else '270+'end as vesting_bucketfrom query_2285669 -- eth),days AS (with days_seq as (SELECTsequence((date('2022-11-30')),date_trunc('day', cast(now() as timestamp)),interval '1' day) as day)SELECTdays.day as dateFROM days_seqCROSS JOIN unnest(day) as days(day) --this is just doing explode like in spark sql),daily_fillers as (select * from days d cross join (select distinct vesting_bucket from data) p),daily_tbv_data as (selectdate_trunc('day',coalesce(bond_time,d.date)) as date,coalesce(w.vesting_bucket,d.vesting_bucket) as quoteSymbol,coalesce(count(distinct evt_tx_hash),0) as daily_bonds,coalesce(sum(coalesce(quoteAmount*quoteTokenPrice,payoutAmount*payoutTokenPrice)),0) as daily_tbvfrom data w right join daily_fillers don date_trunc('day',w.bond_time) = d.dateand w.vesting_bucket = d.vesting_bucketgroup by 1,2