Query editor
WITH trans AS (SELECT tx_hash, sum(value/1e18) as "vl"FROM linea.tracesWHERE "to" IN (0x38dE71124f7a447a01D67945a51eDcE9FF491251)AND CAST(value AS DOUBLE) != 0group by tx_hash),addy AS (SELECT DISTINCT "from", "hash"FROM linea.transactionsWHERE "hash" IN (SELECT "tx_hash" FROM trans)),sendback as (SELECT et."to" as "addy", (trans."vl" - sum(et.value/1e18)) as "diff", et.tx_hash as "tx"FROM linea.traces etLEFT JOIN trans ON et.tx_hash = trans.tx_hashWHERE et.tx_hash IN (SELECT "tx_hash" FROM trans)AND et."from" IN (0x38dE71124f7a447a01D67945a51eDcE9FF491251)AND CAST(et.value AS DOUBLE) != 0GROUP BY et."to", trans."vl", et.tx_hash),nonsend as (SELECT DISTINCT addy."from" as "from", trans."vl" as "volume", et.tx_hash as "tx"FROM linea.traces etLEFT JOIN trans ON et.tx_hash = trans.tx_hashLEFT JOIN addy ON et.tx_hash = addy."hash"WHERE et.tx_hash IN (SELECT "tx_hash" FROM trans)AND et."from" IN (0x38dE71124f7a447a01D67945a51eDcE9FF491251)AND et.tx_hash not in (select "tx" from sendback)AND CAST(et.value AS DOUBLE) = 0),sumnon as (SELECT "from", SUM("volume") as "total", count("tx") as "N"FROM nonsendGroup by "from"),sumsend as (SELECT "addy" as "from", SUM("diff") as "total", count("tx") as "N"FROM sendbackGroup by "addy")SELECT "from", SUM("total") AS "total", (SUM("total"))*(select price from prices.usd_latest where "contract_address" = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2) AS "usd", SUM("N") AS "N"FROM (SELECT "from", "total", "N" FROM sumnonUNION ALLSELECT "from", "total", "N" FROM sumsend) AS combined_dataGROUP BY "from"