Query editor
with user as (select DATE_TRUNC('day', for_time) as for_time, max(total_user) as total_user, max(year_user) as year_user, max(month_user) as month_user, max(week_user) as week_user, max(day_user) as day_user, max(day_trade_user) as trade_user, max(day_fund_user) as fund_userfrom dune.deriw_com.test_user group by DATE_TRUNC('day', for_time)), latest_overall as (SELECT DATE_TRUNC('day', for_time) as for_time,total_value_lock, long_interest, short_interest, open_interest, long_weighting, short_weightingFROM (SELECT *, ROW_NUMBER() OVER (PARTITION BY DATE_TRUNC('day', for_time) ORDER BY for_time desc) as row_numFROM dune.deriw_com.test_overall) as latest_overallWHERE row_num = 1), sum_overall as (SELECT DATE_TRUNC('day', for_time) as for_time,SUM(trading_volume+fund_pool_volume) AS volume,SUM(total_fee) AS feeFROM (dune.deriw_com.test_overall) as latest_overall group by DATE_TRUNC('day', for_time)), latest_position_overall as (SELECT DATE_TRUNC('day', for_time) as for_time,sum(long_interest) as day_long_interest,sum(short_interest) as day_short_interest,sum( if( coin = 'WBTC', long_interest, 0 ) ) AS btc_long_interest, sum( if( coin = 'WBTC', short_interest, 0 ) ) AS btc_short_interest, sum( if( coin = 'WBTC', (long_interest+short_interest), 0 ) ) AS btc_interest,sum( if( coin = 'LINK', long_interest, 0 ) ) AS link_long_interest, sum( if( coin = 'LINK', short_interest, 0 ) ) AS link_short_interest, sum( if( coin = 'LINK', (long_interest+short_interest), 0 ) ) AS link_interest,sum( if( coin = 'WETH', long_interest, 0 ) ) AS eth_long_interest, sum( if( coin = 'WETH', short_interest, 0 ) ) AS eth_short_interest, sum( if( coin = 'WETH', (long_interest+short_interest), 0 ) ) AS eth_interest,sum( if( coin = 'UNI', long_interest, 0 ) ) AS uni_long_interest, sum( if( coin = 'UNI', short_interest, 0 ) ) AS uni_short_interest, sum( if( coin = 'UNI', (long_interest+short_interest), 0 ) ) AS uni_interestFROM (SELECT *, ROW_NUMBER() OVER (PARTITION BY DATE_TRUNC('day', for_time), coin ORDER BY for_time desc) as row_numFROM dune.deriw_com.test_position) as latest_position_overallWHERE row_num = 1 group by DATE_TRUNC('day', for_time)), last_overall as (SELECT DATE_TRUNC('day', for_time) as for_time,day_long_interest as last_long_interest,day_short_interest as last_short_interest,day_long_interest*100/(day_long_interest+day_short_interest) as last_long_weighting,(100-day_long_interest*100/(day_long_interest+day_short_interest)) as last_short_weighting , (day_long_interest+day_short_interest) as last_open_interestFROM latest_position_overall order by for_time desc limit 1)SELECT *,sum(volume) over(order by for_time ROWS between UNBOUNDED PRECEDING and CURRENT ROW) as cumulative_volume,SUM(volume) over (ORDER BY for_time) AS cumulative_volume2,sum(manage_fee+liquidation_fee+trading_fee) over(order by for_time ROWS between UNBOUNDED PRECEDING and CURRENT ROW) as cumulative_fee,sum(manage_fee+liquidation_fee+trading_fee) over(order by for_time ROWS between UNBOUNDED PRECEDING and CURRENT ROW) as cumulative_fee2,SUM(trade_user+fund_user) over(order by for_time ROWS between UNBOUNDED PRECEDING and CURRENT ROW) as total_user2,long_interest/(short_interest+long_interest)*100 as long_dominanceFROM (selectoverall.*,user.total_user,user.year_user,user.month_user,user.week_user,user.day_user, user.trade_user, user.fund_user,latest_overall.total_value_lock ,latest_overall.open_interest,latest_overall.long_interest, latest_overall.short_interest, latest_overall.long_weighting, latest_overall.short_weighting,sum_overall.total_volume, sum_overall.total_fee,period.*,latest_position_overall.btc_interest, latest_position_overall.eth_interest, latest_position_overall.link_interest,latest_position_overall.uni_interest,latest_position_overall.day_long_interest,latest_position_overall.day_short_interest,latest_position_overall.day_long_interest/(latest_position_overall.day_short_interest+latest_position_overall.day_long_interest)*100 as day_long_dominance,100-(latest_position_overall.day_long_interest/(latest_position_overall.day_short_interest+latest_position_overall.day_long_interest)*100) as day_short_dominance,last_overall.last_long_interest , last_overall.last_short_interest ,last_overall.last_long_weighting as last_long_weighting, last_overall.last_short_weighting as last_short_weighting ,last_open_interestfrom (SELECTDATE_TRUNC('day', overall.for_time) AS for_time,SUM(trading_volume+fund_pool_volume) AS volume,