Query editor
with bought as (select * from query_5420650 ),sold as (select * from query_5420655),before_multiplier_correct as (selectbought.userAddress,bought.token,bought.token_bought_amount,bought.token_bought_mint_address,bought.amount_bought_usd,bought.token_buy_price,bought.token_market_cap_buy,sold.token_sold_amount,sold.amount_sold_usd,sold.token_sell_price,sold.token_market_cap_sell,bought.first_traded_date,sold.last_traded_date,case when bought.token_bought_amount - sold.token_sold_amount < 0 then 0 else bought.token_bought_amount - sold.token_sold_amount end as unsold_token,case when sold.amount_sold_usd <= 0 or amount_sold_usd is null then 0when sold.token_sold_amount/bought.token_bought_amount > 1 then 1else sold.token_sold_amount/bought.token_bought_amount end as sold_ratio,case when sold.amount_sold_usd <= 0 or amount_sold_usd is null then 0when sold.token_sold_amount > bought.token_bought_amount then (bought.token_bought_amount*sold.amount_sold_usd/sold.token_sold_amount)- bought.amount_bought_usdelse sold.amount_sold_usd - (sold.token_sold_amount*bought.amount_bought_usd/bought.token_bought_amount) end as realised_Pnl,case when sold.amount_sold_usd <= 0 or amount_sold_usd is null then 0when sold.token_sold_amount > bought.token_bought_amount then (bought.token_bought_amount*sold.amount_sold_usd/sold.token_sold_amount) / bought.amount_bought_usdelse sold.amount_sold_usd / (sold.token_sold_amount*bought.amount_bought_usd/bought.token_bought_amount) end as win_multiple_beforefrom sold left join boughton bought.userAddress = sold.userAddress and bought.token = sold.tokenwhere token_bought_amount != 0 and amount_bought_usd !=0),final as (select *, case when realised_pnl>0 and realised_pnl<1000 then 0else win_multiple_beforeend as win_multiple,CASEWHEN token_sold_amount >= token_bought_amount THEN 0WHEN token_bought_amount IS NULL OR amount_bought_usd IS NULL THEN 0ELSEcoalesce(((token_bought_amount - token_sold_amount) * current_price)- ((token_bought_amount - token_sold_amount) * (amount_bought_usd / token_bought_amount)),0)END AS unrealised_Pnl,CASEWHEN token_sold_amount > token_bought_amount THEN(token_sold_amount -token_bought_amount) * (amount_sold_usd / token_sold_amount)ELSE0END AS transferred_Pnlfrom before_multiplier_correct as a left join(SELECTph.contract_address,avg(ph.price) as current_priceFROM dex_solana.price_hour phWHERE ph.hour = (