-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcampaignCallers.sql
80 lines (69 loc) · 1.46 KB
/
campaignCallers.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
SET @callDateStart = '2018-08-18 00:00:00';
SET @callDateEnd = '2018-08-18 23:59:59';
/* List of callers to Campaign 1000 */
SELECT
campaign_id
, length_in_sec
, status
, phone_number
, user_group
, queue_seconds
, user
, CASE status
WHEN 'DROP' THEN length_in_sec
ELSE length_in_sec - queue_seconds
END AS lengthInSeconds
FROM
vicidial_closer_log
WHERE
call_date BETWEEN @callDateStart AND @callDateEnd
AND campaign_id IN(1000)
AND phone_number IN(0197626262)
LIMIT 10000000;
/* Total Calls */
SELECT
COUNT(campaign_id) AS TotalCalls
FROM
vicidial_closer_log
WHERE
call_date BETWEEN @callDateStart AND @callDateEnd
AND
campaign_id IN(1000)
LIMIT 10000000;
/* Unique callers */
SELECT
COUNT(DISTINCT phone_number) AS UniqueCount
FROM vicidial_closer_log
WHERE
call_date BETWEEN @callDateStart AND @callDateEnd
AND campaign_id IN(1000);
/* Duplicate callers - Sum */
SELECT COUNT(a.phone_number) AS DuplicatesSameDay
FROM (
SELECT
phone_number
, COUNT(phone_number) AS DupesSameDay
FROM vicidial_closer_log
WHERE
call_date BETWEEN @callDateStart AND @callDateEnd
AND campaign_id IN(1000)
GROUP BY
phone_number
HAVING
COUNT(phone_number) > 1
ORDER BY
phone_number) AS a;
/* Duplicate callers - Detail */
SELECT
phone_number
, COUNT(phone_number) AS num_calls
FROM vicidial_closer_log
WHERE
call_date BETWEEN @callDateStart AND @callDateEnd
AND campaign_id IN(1000)
GROUP BY
phone_number
HAVING
COUNT(phone_number) > 1
ORDER BY
phone_number;