Query editor
WITH sonic_active_30 AS (SELECTCOALESCE(namespace, TRY_CAST("to" AS VARCHAR)) AS address,"from",hash,block_time,(TRY_CAST((gas_used * gas_price) AS DOUBLE) / 1e18) AS tx_feeFROM sonic.transactions AS tLEFT JOIN (SELECTaddress,namespaceFROM sonic.contracts) AS fON "to" = addressWHEREDATE(block_time) >= DATE(TRY_CAST('2024-01-01' AS TIMESTAMP)) /* corrected timestamp casting issue */AND success), sonic_active AS (SELECTaddress AS tsonic_protocol,SUM(tx_fee) AS usersFROM sonic_active_30GROUP BYaddressORDER BYSUM(tx_fee) DESCLIMIT 15)SELECTDATE_TRUNC('day', block_time) AS date_time,protocol,-- SUM(b."Total Gas Spent"/1e9)/(COUNT(b."Total Gas Spent")) AS total_gas_spent,SUM(tx_fee) AS tx_feesFROM (SELECT*,CASE WHEN tsonic_protocol IS NULL THEN 'Other' ELSE tsonic_protocol END AS protocolFROM sonic_active_30LEFT JOIN sonic_activeON tsonic_protocol = address)where DATE_TRUNC('day', block_time) < date(current_timestamp)GROUP BY1,2