Query editor
--查找一个用户在某个合约的交易盈利--获取起始交易时间间隔N小时内的用户购买清单with target_pair_info as (selectblock_time,project_contract_address,tx_from,tx_to,taker,amount_usd,token_bought_amount_raw,token_sold_amount_raw,(case when token_sold_address = 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c then -amount_usdelse amount_usd end) amount_usd_new,case when token_bought_address = 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c then token_sold_address else token_bought_address end as contract_address,min(block_time) over (partition by project_contract_address) as earliest_trade_timefrom dex.tradeswhereblockchain = 'bnb'AND project = 'pancakeswap'and tx_from = {{total_tx_from_user}}and block_time> cast('{{tatal_start_time_user}}' as timestamp)and block_time< cast('{{tatal_start_time_user}}' as timestamp) + interval '{{interval_day_total}}' day),huiju as (selectearliest_trade_time,project_contract_address,contract_address,sum(case when amount_usd_new<0 then 1 else 0 end) as buy_times,sum(case when amount_usd_new>0 then 1 else 0 end) as sell_times,sum(case when amount_usd_new<0 then amount_usd else 0 end) as buy_usd,sum(case when amount_usd_new>0 then amount_usd else 0 end) as sell_usd,sum(case when amount_usd_new<0 then token_bought_amount_raw else 0 end) as buy_amount_raw,sum(case when amount_usd_new>0 then token_sold_amount_raw else 0 end) as sell_amount_raw,sum(case when amount_usd_new<0 then token_bought_amount_raw else 0 end) - sum(case when amount_usd_new>0 then token_sold_amount_raw else 0 end) buy_sub_sell_amount_raw,sum(amount_usd_new) as profit_usdfrom target_pair_info group by 1,2,3 order by 1 asc)selectsum(profit_usd) as profit_usd,sum(buy_times) buy_times,sum(sell_times) sell_times from huiju where1=1and buy_sub_sell_amount_raw>=0