Query editor
WITH all_ AS (SELECTtx_hashFROM dex."trades" AS dWHEREd.blockchain = 'ethereum'AND tx_to = 0x881d40237659c251811cec9c364ef91dc08d300cAND amount_usd > 0AND block_time > CURRENT_TIMESTAMP - INTERVAL '30' dayGROUP BY1), table_ AS (SELECTtx_hash,evt_index,project,token_sold_address AS a,token_bought_address AS b,amount_usdFROM dex."trades"WHEREblockchain = 'ethereum'AND tx_hash IN (SELECTtx_hashFROM all_)AND tx_to = 0x881d40237659c251811cec9c364ef91dc08d300c), xx AS (SELECTtx_hash,MAX(evt_index) AS indexFROM table_GROUP BY1), yy AS (SELECT DISTINCTtx_hash,aFROM table_WHEREevt_index IN (SELECTindexFROM xx)), fin AS (SELECT DISTINCTyy.tx_hash,table_.amount_usdFROM yyLEFT JOIN table_ON yy.a = table_.a AND yy.tx_hash = table_.tx_hash), time AS (SELECT DISTINCTfin.tx_hash,block_time,tx_fromFROM finLEFT JOIN dex."trades" AS d