with base as (select tx_id,
case when tx_id in (select tx_id from thorchain.core.fact_refund_events) then 'Refunded Swaps'
else 'Succeeded Swaps'
end as swap_category,
max(from_amount_usd) as swap_volume,
tx_id as txHash,
1 as numbering
from thorchain.core.fact_swaps
where affiliate_address = 'te'
group by 1
order by 3 desc)
select swap_volume,
txHash
from base
group by 1,2