Query editor
------------------DIMS---------------With time_table as (SELECT date_add('hour', step, day) AS hourFROM unnest(SEQUENCE(CAST('2024-05-01' AS TIMESTAMP), current_date, INTERVAL '1' day)) AS t(day)----- generate a sequence (this will create the number of rows necessary for each day)CROSS JOIN (SELECT * FROM unnest(SEQUENCE(1, 24, 1)) AS t(step))), time_table_12h as (select hour from time_tablewhere (extract(HOUR FROM hour) in (0, 12)))---------------Facts-----------------, trade_base_op as (select project, block_date, block_time, amount_usd, case when token_bought_address = 0x8c6f28f2F1A3C87F0f938b96d27520d9751ec8d9 then token_bought_amountelse token_sold_amountend as susd_amountfrom dex.tradeswhere blockchain = 'optimism'and (token_bought_address = 0x8c6f28f2F1A3C87F0f938b96d27520d9751ec8d9or token_sold_address = 0x8c6f28f2F1A3C87F0f938b96d27520d9751ec8d9)and block_date > timestamp'2024-05-01'and amount_usd > 10), trade_base_eth as (select project, block_date, block_time, amount_usd, case when token_bought_address = 0x57Ab1ec28D129707052df4dF418D58a2D46d5f51 then token_bought_amountelse token_sold_amountend as susd_amountfrom dex.tradeswhere blockchain = 'ethereum'and (token_bought_address = 0x57Ab1ec28D129707052df4dF418D58a2D46d5f51or token_sold_address = 0x57Ab1ec28D129707052df4dF418D58a2D46d5f51)and block_date > timestamp'2024-05-01'and amount_usd > 10), swap_base as (select ('Optimism') as project, block_date, block_time, amount_usd, susd_amount, amount_usd / susd_amount as peg, case when extract(HOUR FROM block_time) >= 0 and extract(HOUR FROM block_time) < 12 then date_trunc('day', block_time)else date_trunc('day', block_time) + interval '12' hour end as hour_normalizedfrom trade_base_opunion allselect ('Ethereum'), block_date, block_time, amount_usd, susd_amount, amount_usd / susd_amount as peg, case when extract(HOUR FROM block_time) >= 0 and extract(HOUR FROM block_time) < 12 then date_trunc('day', block_time)else date_trunc('day', block_time) + interval '12' hour end as hour_normalizedfrom trade_base_eth)--------------------------Abstractions---------------------------------------, time_table_final as (select hour, project from time_table_12hcross join (select distinct project from swap_base))