with recursive 
count_rep as (
select phone, round(amount / 4) cards from lotters_data
where type_lotters = 'count_rep_lotters' and round(amount / 4) > 0 and date {filter_date}
),

cards_count_rep1 as (
select phone, cards, 1 n from count_rep 
union all select  phone, cards, n + 1 from cards_count_rep1
where n < cards),

cards_count_rep2 as (	
select phone,cards, 1 n from count_rep
where phone not in (select phone from lotters_data where amount > 0 and type_lotters = 'count_no_rep_lotters')
union all select  phone, cards, n + 1 from cards_count_rep2
where n < cards),

count_add as (
select phone, amount cards, 1 n from lotters_data 
where type_lotters = 'count_add_lotters' and amount > 0 and date {filter_date}
union all select  phone, cards, n + 1 from count_add
where n < cards),

cards_num as (
select row_number() over (order by n) rn, phone
from
(select * from cards_count_rep1
union all
select * from cards_count_rep2
union all
select * from count_add) crds) 

select count(*) cnt from cards_num {filter}
