Query editor
WITH-- Sum of tradingFeesEarned for each user from LiquidityProvided tableLiquidityProvided AS (SELECTliquidityProvider AS provider,SUM(tradingFeesEarned/1e18) AS TotalFeesEarnedFROMincrement_zksync.ClearingHouse_evt_LiquidityProvidedWHEREevt_block_time >= date_trunc('month', current_date) ANDevt_block_time < date_trunc('month', current_date) + INTERVAL '1' MONTHGROUP BYliquidityProvider),-- Sum of profit for each user from LiquidityRemoved tableLiquidityRemoved AS (SELECTliquidityProvider AS provider,SUM(profit/1e18) AS TotalProfitFROMincrement_zksync.ClearingHouse_evt_LiquidityRemovedWHEREevt_block_time >= date_trunc('month', current_date) ANDevt_block_time < date_trunc('month', current_date) + INTERVAL '1' MONTHGROUP BYliquidityProvider),-- Sum of all "amount" per "account" from ETHPerpetual_evt_FundingPaid tableETHPerpetualFundingPaid AS (SELECTaccount AS account_provider,SUM(amount/1e18) AS TotalFundingPaidFROMincrement_zksync.ETHPerpetual_evt_FundingPaidWHEREisTrader = false -- Filter out records where isTrader is falseGROUP BYaccount),-- Final query to sum up results from all CTEs for each user, rank them, and exclude rows with TotalEarnings of 0RankedResults AS (SELECTCOALESCE(lp.provider, lr.provider, fp.account_provider) AS Provider,COALESCE(lp.TotalFeesEarned, 0) AS TotalFeesEarned,COALESCE(lr.TotalProfit, 0) AS TotalProfit,COALESCE(fp.TotalFundingPaid, 0) AS TotalFundingPaidFROMLiquidityProvided lpFULL OUTER JOINLiquidityRemoved lr ON lp.provider = lr.providerFULL OUTER JOINETHPerpetualFundingPaid fp ON lp.provider = fp.account_provider OR lr.provider = fp.account_providerWHERECOALESCE(lp.TotalFeesEarned, 0) + COALESCE(lr.TotalProfit, 0) != 0 -- This excludes rows where TotalEarnings is 0AND COALESCE(lp.provider, lr.provider, fp.account_provider) NOT IN (0x294dd239669a5876e5f1704dafaae0fa47adb98d, 0xdf78Cdb02FfBF2925fd3a4e9883467E6768edF6B) -- Exclude the specified liquidity provider),