Query editor
WITH uni_temp as (SELECTtx_hash,amount_usd,tx_from,taker,project_contract_address,version,CASE WHEN token_pair is null then 'Not Labelled' else token_pair end as token_pair,CASE WHEN version in ('1','2') THEN .003 * amount_usd ELSE (fee / CAST(1e6 AS DOUBLE)) * amount_usd end as feeFROM dex.tradesLEFT JOIN uniswap_v3_ethereum.Factory_call_createPool AS c ON project_contract_address = c.output_poolWHERE blockchain = 'ethereum'and DATE(block_time) >= current_date - interval '365' dayand project = 'uniswap'),dex as (SELECTtx_from,COUNT(DISTINCT(tx_hash)) as number_of_swaps,AVG(amount_usd) as avg_trade_size,SUM(amount_usd) as total_volume,SUM(fee) as total_fees,COUNT(DISTINCT(token_pair)) as token_pairsFROM uni_tempGROUP BY tx_from),top_vol as (SELECTtx_from,number_of_swaps,avg_trade_size,total_volumeFROM dex--Removing 1inch and other big aggregatorsWHERE tx_from not in (0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45,0x220bda5c8994804ac96ebe4df184d25e5c2196d4,0xf2f400c138f9fb900576263af0bc7fcde2b1b8a8,0x74de5d4fcbf63e00296fd95d33236b9794016631,0x2057cfb9fd11837d61b294d514c5bd03e5e7189a)ORDER BY total_volume DESC),all_users as (SELECT1 as key_join,SUM(number_of_swaps) as all_swaps,SUM(total_volume) as all_volumeFROM dex),temp as (SELECTROW_NUMBER() OVER (ORDER BY total_volume DESC) as ranking,tx_from as address,number_of_swaps,total_volume,total_volume / all_volume as perc_vol,avg_trade_size,number_of_swaps / all_swaps as perc_swaps,ROW_NUMBER() OVER (ORDER BY total_volume ASC) as total_tradersFROM top_volLEFT JOIN all_users ON 1 = key_join