is there a way to replace/simplified the following code with while/loop function? I need to loop it while items < specific number or variable. Thank you!
select
count(distinct wallet) filter (where items >= 3 and items < 6) +
count(distinct wallet) filter (where items >= 6 and items < 9) +
count(distinct wallet) filter (where items >= 9 and items < 12) +
count(distinct wallet) filter (where items >= 12 and items < 15) as total_items
from
agg
where items > 0