﻿
select max(b.id) as id_eventos, max(a.id_bilhetes) as id_bilhetes
  from ast_bilhetes a, ast_eventos_dacs b
 where b.uid2 = a.uniqueid
   and a.calldate::date <  (now()::date -5)


select count(*) from ast_eventos_dacs where id <= 0;
select count(*) from ast_bilhetes where id_bilhetes <= 0;

 --  delete from ast_bilhetes where id_bilhetes <= 4298634
 --  delete from ast_eventos_dacs where id <= 5434440



 