with not_bots as (
select
count (*) as swaps, trader
from
terra.swaps
WHERE
block_timestamp > CURRENT_DATE - 30
GROUP BY
2
HAVING
swaps < 500
),
bots as (
select
count (*) as swaps, trader
from
terra.swaps
WHERE
block_timestamp > CURRENT_DATE - 30
GROUP BY
2
HAVING
swaps > 500
)
SELECT
count (*) as swapped,
(SELECT sum(swaps) from bots) as bots,
(SELECT sum(swaps) from not_bots) as not_bots,
ROUND((SELECT sum(swaps) from bots) * 100/ count (*), 1) as percentage_bots
from
terra.swaps
WHERE
block_timestamp > CURRENT_DATE - 30