with
a as (
select
nft_to_address as wallets,
'1' as flag
FROM ethereum.core.ez_nft_transfers
where (nft_address =lower('0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d')
)
union all
SELECT
nft_from_address as wallets,
'-1' as flag
FROM ethereum.core.ez_nft_transfers
where (nft_address =lower('0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d')
)
),
b as (
select
wallets ,
sum(flag) as nfts
from a
group by 1
having 2 > 0
order by 2 desc)
select
count(distinct wallets) as users,
case
when nfts = 1 then '1'
when nfts = 2 then '2'
when nfts = 3 then '3'