Query editor
WITH-- Total Bitcoin Supplytotal_supply AS (SELECT21000000 AS max_bitcoins -- Maximum supply of Bitcoin),-- Calculate all mined Bitcoin so farmined_bitcoin AS (SELECTSUM(b.mint_reward) AS total_minedFROMbitcoin.blocks b -- Adjusted to the correct table nameWHEREb.height <= (SELECT MAX(height) FROM bitcoin.blocks) -- Only consider blocks up to the current height)-- Produce rows for mined and unmined BitcoinSELECT'Mined Bitcoin' AS name,mb.total_mined AS balance,1 AS sort_orderFROMmined_bitcoin mbUNION ALLSELECT'Unmined Bitcoin' AS name,ts.max_bitcoins - mb.total_mined AS balance,2 AS sort_orderFROMtotal_supply ts, mined_bitcoin mb-- Ensure "Mined Bitcoin" appears firstORDER BY sort_order;