Query editor
WITH-- Raw transactions to/from Four.meme contractraw_txns AS (SELECT"from" AS user_address,"to" AS contract,hash AS tx_hash,block_time,value AS bnb_value, -- BNB sent with tx (buys)data -- call data (to detect sells)FROM bnb.transactionsWHERE-- Four.meme bonding curve contract address"to" = 0xEC4549caDcE5DA21Df6E6422d448034B5233bFbC OR "to" = 0x5c952063c7fc8610FFDB798152D69F0B9550762bAND block_time >= NOW() - INTERVAL '3' MONTHAND success = true),-- Classify each tx as BUY (BNB in > 0) or SELL (BNB in = 0)classified AS (SELECTuser_address,tx_hash,block_time,CASEWHEN bnb_value > CAST(0 AS UINT256) THEN 'BUY'ELSE 'SELL'END AS trade_type,bnb_valueFROM raw_txns),-- Aggregate per useruser_stats AS (SELECTuser_address,COUNT(*) AS total_trades,COUNT(CASE WHEN trade_type = 'BUY' THEN 1 END) AS total_buys,COUNT(CASE WHEN trade_type = 'SELL' THEN 1 END) AS total_sells,-- Total BNB spent buyingSUM(CASE WHEN trade_type = 'BUY'THEN CAST(bnb_value AS DOUBLE) / 1e18ELSE 0 END) AS total_bnb_spent,ROUND(100.0 * COUNT(CASE WHEN trade_type = 'SELL' THEN 1 END)/ NULLIF(COUNT(*), 0),2) AS sell_ratio_pctFROM classifiedGROUP BY 1)SELECTuser_address,total_trades,total_buys,