Query editor
WITH bounds AS (SELECTDATE_TRUNC('day', NOW()) AS end_ts,DATE_TRUNC('day', NOW()) - INTERVAL '3' MONTH AS start_ts),details AS (SELECTDATE_TRUNC('day', a.block_date) AS day,a."tx_from" AS "from",a."to",a.amount,a.amount_usd,a.contract_address,a.tx_hashFROM tokens.transfers aJOIN bounds sON a.block_time >= s.start_ts AND a.block_time < s.end_tsJOIN query_4058067 bON a.contract_address = b.contract_addressWHERE a.blockchain = 'bnb'AND a.contract_address IN (0x55d398326f99059ff775485246999027b3197955, -- USDT (BNB)0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d -- USDC (BNB))),holders AS (SELECTday,"from" AS address,SUM(amount) AS amount,COUNT(DISTINCT tx_hash) AS txnsFROM detailsGROUP BY 1, 2),buckets AS (SELECTday,SUM(CASE WHEN amount_usd < 100 THEN 1 ELSE 0 END) AS txs_lt_100,SUM(CASE WHEN amount_usd >= 100 AND amount_usd < 500 THEN 1 ELSE 0 END) AS txs_100_499,SUM(CASE WHEN amount_usd >= 500 AND amount_usd < 1000 THEN 1 ELSE 0 END) AS txs_500_999,SUM(CASE WHEN amount_usd >= 1000 AND amount_usd < 10000 THEN 1 ELSE 0 END) AS txs_1k_9k,SUM(CASE WHEN amount_usd >= 10000 THEN 1 ELSE 0 END) AS txs_10k_plus,COUNT(*) AS txs_totalFROM detailsGROUP BY 1)SELECTh.day,COUNT(DISTINCT h.address) AS senders,SUM(h.amount) AS transfer_amount,SUM(h.txns) AS txns,SUM(h.amount) / NULLIF(COUNT(DISTINCT h.address), 0) AS avg_transfer,b.txs_total,b.txs_lt_100,b.txs_100_499,b.txs_500_999,b.txs_1k_9k,b.txs_10k_plusFROM holders hJOIN buckets b ON b.day = h.day