Query editor
with refunds as (selectentity_id,sum(refund_amount) as refund_amountfrom (select*,entityID as entity_id,addr as address,amount*pow(10,-6) as refund_amountfrommegaeth_ethereum.megasale_evt_bidcancelled)group by entity_id),bids as (selectentity_id,sum(bid_amount) as bid_amountfrom (select*,entityID as entity_id,json_value(bid, 'lax $.amount' returning bigint)*pow(10,-6) as bid_amountfrommegaeth_ethereum.megasale_evt_bidplaced)group by entity_id)-- select-- sum(refund_amount) as total_refunds,-- avg(refund_amount) as avg_refunds,-- count(*) as refund_txs-- from-- refundsselectsum(case when refund_amount is null then bid_amount end) as unrefunded_amount,sum(case when allocation = 0 then bid_amount end) as full_refund,sum(case when allocation >0 then allocation end) as partial_allofrom (selectentity_id,bid_amount,refund_amount,bid_amount - refund_amount as allocationfrombidsleft join refunds using(entity_id))