Query editor
with reinv as (select"tx"."from","tx".block_time,"tx".hash,substring("tx"."data", 1,10) function,"tx".data,"ex"."positionId",-- "erc_tf".value(cast("erc_tf".value as double) / pow(10, "tok".decimals)) * median_price "value"from alpha_homora_v2_optimism.homora_bank_call_putCollateral "hpc"join optimism.transactions "tx" on "tx".hash = "hpc".call_tx_hashjoin alpha_homora_v2_optimism."homora_bank_call_execute" "ex" on "ex"."call_tx_hash" = "tx"."hash"join erc20_optimism.evt_Transfer "erc_tf" on "erc_tf".evt_tx_hash = "tx".hash and "tx"."from" = "erc_tf"."from"join tokens_optimism.erc20 "tok" on "tok".contract_address = "erc_tf".contract_addressjoin dex.prices "pr" on "pr".contract_address = "erc_tf".contract_address and DATE_TRUNC('hour', "tx".block_time) = "pr".hour and "blockchain" = 'optimism'where-- "tx"."hash" = 0x51e4fe991fedea8330586b3494f6f7a97b087c39130a658cd7cd27cae6fad5f8"tx"."from" = 0x3bb4893b1ef4b9e2c2db0ec26ac3f078e5fcbbf8and "ex".positionId != '0'and length("tx".data) = 714order by "tx".block_time asc,"ex"."positionId","tok".symbol asc),days AS(with days_seq as (SELECTsequence((SELECT cast(min(date_trunc('day', block_time)) as timestamp) day FROM "reinv" tr), date_trunc('day', cast(now() as timestamp)), interval '1' day) as day)SELECTdays.dayFROM days_seqCROSS JOIN unnest(day) as days(day) --this is just doing explode like in spark sql)select days.day,"positionId",value,sum("value") over ( order by days.day) cum_sumfrom days left join reinv on days.day = date_trunc('day', reinv.block_time)