Query editor
WITH coinbase AS (SELECTDATE(block_time) AS d,idFROM bitcoin.transactionsWHERE EXTRACT(YEAR FROM block_time) = 2012AND is_coinbase = TRUEAND input_count = 1AND input_value = 0),cb_outputs AS (SELECTc.d,o.index AS idx,c.id AS tx_id,o.value AS value,o.address,o.script_hexFROM bitcoin.outputs oJOIN coinbase c ON c.id = o.tx_idWHERE o.type != 'nonstandard')SELECTSUM(CASE WHEN i.spent_tx_id IS NULL THEN 1 ELSE 0 END) AS unspent_outputs,SUM(CASE WHEN i.spent_tx_id IS NULL THEN co.value ELSE 0 END) AS unspent_value,COUNT(*) AS total_outputs,SUM(co.value) AS total_valueFROM cb_outputs coLEFT JOIN bitcoin.inputs iON i.spent_tx_id = co.tx_idAND i.spent_output_number = co.idx;