Query editor
WITH coinbase_outputs AS (SELECTo.tx_id,o.block_height AS created_height,o.valueFROM bitcoin.outputs oWHERE o.tx_id IN (SELECT idFROM bitcoin.transactionsWHERE is_coinbase = trueAND block_date >= DATE '2023-01-01')),spent AS (SELECTi.spent_tx_id,i.block_height AS spent_height,i.block_date AS spent_dateFROM bitcoin.inputs iWHERE i.spent_tx_id IN (SELECT tx_id FROM coinbase_outputs)AND i.block_date >= DATE '2024-01-01')SELECTDATE_TRUNC('week', s.spent_date) AS week,AVG(s.spent_height - c.created_height) AS avg_holding_blocks,AVG((s.spent_height - c.created_height) * 10.0 / 60 / 24) AS avg_holding_days,COUNT(*) AS tx_countFROM spent sJOIN coinbase_outputs c ON s.spent_tx_id = c.tx_idGROUP BY 1ORDER BY 1