Query editor
WITH coinbase AS (SELECTblock_date AS creation_date,id,output_valueFROM bitcoin.transactionsWHERE EXTRACT(YEAR FROM block_time) = 2024AND is_coinbase = TRUEAND input_count = 1AND input_value = 0),mined AS (SELECTdate_format(creation_date, '%Y') AS creation_year,SUM(output_value) AS main_valueFROM coinbaseGROUP BY 1),spent_by_year AS (SELECTdate_format(c.creation_date, '%Y') AS creation_year,date_format(i.block_date, '%Y') AS spent_year,SUM(i.value) AS spent_valueFROM coinbase cLEFT JOIN bitcoin.inputs iON c.id = i.spent_tx_idWHERE i.block_date IS NOT NULLGROUP BY 1,2),spent_totals AS (SELECT creation_year, SUM(spent_value) AS spent_totalFROM spent_by_yearGROUP BY 1),unspent AS (SELECTm.creation_year,CAST('Unspent' AS varchar) AS spent_year,(m.main_value - COALESCE(st.spent_total, 0)) AS spent_value,(m.main_value - COALESCE(st.spent_total, 0)) * 100.0 / m.main_value AS spent_pctFROM mined mLEFT JOIN spent_totals stON st.creation_year = m.creation_year)SELECTs.creation_year,s.spent_year,ROUND(m.main_value) AS main_value,ROUND(s.spent_value) AS spent_value,ROUND(100.0 * s.spent_value / m.main_value, 4) AS spent_pctFROM spent_by_year sJOIN mined mON m.creation_year = s.creation_yearUNION ALL