Query editor
-- STEP 1 Rental payWITH rent_paid as (SELECTDATE_TRUNC('day',evt_block_time) as day,tokenID,sum(amount) as amountFROM landxfinance_ethereum.RentFoundation_evt_rentPaidGROUP BY 1,2),initial_rent_paid as (SELECTDATE_TRUNC('day',evt_block_time) as day,tokenID,sum(amount) as amountFROM landxfinance_ethereum.RentFoundation_evt_initialRentPaidGROUP BY 1,2),initial_rent_paid_raw as (SELECTtokenID,evt_block_time as count_second,CAST(amount AS DOUBLE) / 31536000 as will_rent_paid-- (CAST(amount AS DOUBLE) / 31536000)*DATE_DIFF('second',evt_block_time,NOW()) as rent_diffFROM landxfinance_ethereum.RentFoundation_evt_initialRentPaid),add_both_paid as (SELECT * FROM initial_rent_paidUNION ALLSELECT * FROM rent_paid),gen_data as (SELECTd.day,n.xtokens,n.idFROM query_3830213 dCROSS JOIN query_3919975 n),add_data as (SELECTd.day,d.xtokens as name,COALESCE(t.amount,0) as amount,r.count_second,r.will_rent_paid,r.will_rent_paid*DATE_DIFF('second',r.count_second,d.day) as rent_diffFROM gen_data dLEFT JOIN initial_rent_paid_raw rON d.id = r.tokenIDLEFT JOIN add_both_paid tON t.day = d.day and t.tokenID = d.id),total_paid as (SELECTday,name,amount,rent_diff,sum(amount) OVER (PARTITION BY name ORDER BY day) as total_amount_paid