Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set @StartDate = '2018-03-15 00:00:00';
- set @EndDate = '2018-03-15 23:59:59';
- DELIMITER //
- CREATE FUNCTION fn_GetStartDate ()
- RETURNS DATETIME
- DETERMINISTIC NO SQL
- BEGIN
- RETURN @StartDate;
- END//
- DELIMITER ;
- DELIMITER //
- CREATE FUNCTION fn_GetEndDate ()
- RETURNS DATETIME
- DETERMINISTIC NO SQL
- BEGIN
- RETURN @EndDate;
- END//
- DELIMITER ;
- CREATE OR REPLACE VIEW cdr_call AS
- select
- i.id AS id,
- i.answer AS answer,
- i.end AS end,
- i.src AS src,
- i.dst AS dst,
- i.channel AS channel,
- i.dstchannel AS dstchannel,
- i.dcontext AS dcontext,
- i.lastapp AS lastapp,
- i.lastdata AS lastdata,
- (case
- when ((i.lastapp = 'Playback') and (i.lastdata = 'invalid')) then 'NO ANSWER'
- when (i.lastapp = 'Queue') then 'NO ANSWER'
- when (i.dcontext = 'play-busy') then 'BUSY'
- when ((i.hangupcause = 1) and (i.disposition = 'ANSWERED')) then 'BUSY'
- when (i.lastapp = 'VoiceMail') then 'VOICEMAIL'
- when (((i.dcontext like 'ivr%') and (i.disposition = 'NO ANSWER')) or (((i.lastapp like 'BackGround') or (i.lastapp = 'Dial')) and (i.dstchannel = ''))) then 'NO ANSWER'
- when (i.lastapp = 'WaitExten') then 'NO ANSWER' else i.disposition end
- ) AS disposition,
- i.amaflags AS amaflags,
- i.accountcode AS accountcode,
- i.uniqueid AS uniqueid,
- i.userfield AS userfield,
- i.record AS record,
- i.caller_num AS caller_num,
- i.called_num AS called_num,
- i.hops AS hops,
- i.incoming AS incoming,
- i.outgoing AS outgoing,
- i.hangupcause AS hangupcause,
- i.queue AS queue,
- i.linkedid AS linkedid,
- i.uploaded AS uploaded,
- i.sent AS sent,
- i.transfer AS transfer,
- ifnull(i.incoming,i.outgoing) AS did,
- ends.duration as duration,
- ends.billsec as billsec,
- (ends.duration - ends.billsec) AS wait,
- ends.`start` as `start`
- from (select
- max(a.id) as latest_id,
- max(`start`) as `start`,
- max(a.duration) as duration,
- max(a.billsec) as billsec,
- count(1) as count
- from ast_cdr_adaptive a
- where
- ((a.hops between 0 and 1) and
- ((a.answer is not null) or
- (isnull(a.answer) and isnull(a.incoming) and (a.outgoing is not null))) and
- a.start BETWEEN fn_GetStartDate() AND fn_GetEndDate())
- group by a.linkedid order by a.`end` desc) as ends
- inner join ast_cdr_adaptive i on (i.id = ends.latest_id);
- -- пример как run-анать запросы
- use virt352;
- set @StartDate = '2018-03-12 00:00:00';
- set @EndDate = '2018-03-15 23:59:59';
- select count(*) from cdr_call;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement