﻿select a.calldate, a.src, a.dst, a.uniqueid, a.userfield, a.duration, a.billsec, a.flag_fila,  b.tplg_codigo, b.tplg_descricao, tplg_tipo
  from pbx_bilhetes a, pbx_tipo_ligacao b
 where b.tplg_codigo = a.tipo_chamada
   and a.data_bilhete >= '2018-03-01'
   and a.data_bilhete <= '2018-03-31'
   and a.lastapp <> 'Transferred Call'
  --and b.tplg_codigo = 25
 --  and flag_fila = 'S'


--select * from pbx_bilhetes  limit 1



/*
select * from pbx_tipo_ligacao;

select count(*)
  from pbx_bilhetes a
 where 1=1
   and a.data_bilhete >= '2018-03-01'
   and a.data_bilhete <= '2018-03-31'
   and a.lastapp <> 'Transferred Call'
  -- and a.flag_fila = 'S'
   and exists(select '' from  pbx_eventos_dacs where uid2 = a.uniqueid)
   */