Query editor
--获取起始交易时间间隔N小时内的用户购买清单with target_pair_info as (selectblock_time,project_contract_address,tx_from,tx_to,taker,(case when token_sold_address = 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c then -amount_usdelse amount_usd end) amount_usd_newfrom dex.tradeswhereblockchain = 'bnb'AND project = 'pancakeswap'and project_contract_address = {{_in_project_contract_txfromto}}and block_time> cast('{{_in_timetomarket}}' as timestamp)and block_time< cast('{{_in_timetomarket}}' as timestamp) + interval '{{interval_hours}}' hour),trade_detail as (with trade_detail_sub as (selecttx_from,(case when token_sold_address = 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c then -amount_usdelse amount_usd end) amount_usd_new,row_number() over (partition by tx_from order by block_time) as row_numberfrom dex.tradeswhereblockchain = 'bnb'AND project = 'pancakeswap'and project_contract_address = {{_in_project_contract_txfromto}}and block_time> cast('{{_in_timetomarket}}' as timestamp)),trade_detail_sub2 as (selecttx_from,sum(amount_usd_new) profit_usd,sum(case when amount_usd_new>0 then 1 else 0 end) as sell_times,sum(case when amount_usd_new<0 then 1 else 0 end) as buy_timesfrom trade_detail_subgroup by 1),trade_detail_sub3 as (selecttx_from,case when amount_usd_new<0 then 'buy' else 'sell' end as first_order_orientfrom trade_detail_subwhererow_number = 1)