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

insert into lotters_data (phone,amount,type_lotters,type_user,date) 
select Phone,amount,'count_add_lotters',1,date(NOW() - INTERVAL 5 HOUR) from
(select Phone, count(*) amount
from cards_data_base join users on cards_data_base.user_id = users.user_id
where date(cards_data_base.ts_create + INTERVAL -(5) HOUR) = date(NOW() - INTERVAL 5 HOUR) and card_import_source is null  group by users.phone) count_add  ;

insert into lotters_data (phone,amount,type_lotters,type_user,date) 
select Phone,amount,'count_rep_lotters',1,date(NOW() - INTERVAL 5 HOUR) from
(select Phone,count(*) amount
from replog_data join users on replog_data.user_id = users.user_id
where date = date(NOW() - INTERVAL 5 HOUR) group by users.phone) count_rep;

insert into lotters_data (phone,amount,type_lotters,type_user,date) 
select Phone,amount,'count_no_rep_lotters',1,date(NOW() - INTERVAL 5 HOUR) from
(select Phone, count(*) amount
from cards_data_base join users on cards_data_base.user_id = users.user_id
where cards_data_base.next_timing = date(NOW() - INTERVAL 5 HOUR)  group by users.phone) count_no_rep ;


