delete from lotters_data where type_user = 1 and date = date(NOW() - INTERVAL 5 HOUR) and phone = &1;

insert into lotters_data (phone,amount,type_lotters,type_user,date) 
select &1,amount,'count_add_lotters',1,date(NOW() - INTERVAL 5 HOUR) from
(select &1, count(*) amount
from cards_data_base 
where date(cards_data_base.ts_create - INTERVAL 5 HOUR) = date(NOW() - INTERVAL 5 HOUR)
and card_import_source is null and user_id = &2 ) count_add  ;

insert into lotters_data (phone,amount,type_lotters,type_user,date) 
select &1,amount,'count_rep_lotters',1,date(NOW() - INTERVAL 5 HOUR) from
(select &1,count(*) amount
from replog_data 
where date = date(NOW() - INTERVAL 5 HOUR) and user_id = &2 ) count_rep;


insert into lotters_data (phone,amount,type_lotters,type_user,date) 
select &1,amount,'count_no_rep_lotters',1,date(NOW() - INTERVAL 5 HOUR) from
(select &1, count(*) amount
from cards_data_base 
where cards_data_base.next_timing = date(NOW() - INTERVAL 5 HOUR) and user_id = &2 ) count_no_rep ;

