with calculate_vol as (
select
(case
when swap_to_asset_id=226701642 then swap_to_amount
when swap_from_asset_id=226701642 then swap_from_amount
end
) as volume
,date_trunc('day', block_timestamp) as swapdate
, swap_program
,(case
when swap_from_asset_id=226701642 then swap_to_asset_id end
) as asset_id
from algorand.swaps
where swap_to_asset_id=226701642 or swap_from_asset_id=226701642
)
select sum(volume),swapdate,swap_program from calculate_vol
group by swapdate,swap_program