with list as (
select
date_trunc('month', block_timestamp) as time,
tx_from,
tx_to,
count(*) as number_of_txs,
count_if(tx_status != 'SUCCEEDED') as number_of_failed_txs,
number_of_failed_txs * 100 / number_of_txs as perc
from terra.transactions
group by time, tx_from, tx_to
)
select
time,
case when perc > 50 then 'Pair with more than 50% failure rate' else 'Pair with less than 50% failure rate' end as "User profile",
sum(number_of_failed_txs) as number_of_failed_txs
from list
group by 1, 2