【发布时间】:2019-09-10 07:07:19
【问题描述】:
我有 queue_log 表,其中包含单个呼叫记录的多个记录,其中唯一列 call_id 重复单个呼叫行数。
我有以下查询。
select case when verb="did" then data1 end as did,
case when verb='CONNECT' then "Answered" else "Missed" end as status,
queue,verb,
case when verb in ('connect') then agent end as agent
from queue_log
where created between '2019-09-01' and '2019-09-09'
group by call_id
having verb in ('did','connect','enterqueue','completecaller','completeagent','abandon','exitwithtimeout');
让我们再解释一下。 如果我在 queue_log 中有一个调用,它有一条记录,verb=did 和第二个verb=connect,然后第三条带有verb in ('completecaller','completeagent') 和所有行的call_id 相同。
如果在任何一行中有动词 connect,则此调用将被应答,否则 Abandon。
以上查询返回所有放弃调用。同时也有接听电话。
以下是示例数据。
$
+-------+-----+------------+------------------+-------+----------------+-----------+----------------+-------+------+----------+------------------+-------+-------+-------+-----------+---------------------+
| id | idd | time_id | call_id | queue | verb | queuename | agent | event | data | data1 | data2 | data3 | data4 | data5 | partition | created |
+-------+-----+------------+------------------+-------+----------------+-----------+----------------+-------+------+----------+------------------+-------+-------+-------+-----------+---------------------+
| 41972 | 0 | 1567386039 | 1567386027.11981 | 4001 | DID | | NONE | | | 63897811 | | | | | P001 | 2019-09-02 09:00:39 |
| 41973 | 0 | 1567386039 | 1567386027.11981 | 4001 | ENTERQUEUE | | NONE | | | | 63038768 | 1 | | | P001 | 2019-09-02 09:00:39 |
| 41974 | 0 | 1567386049 | 1567386027.11981 | 4001 | CONNECT | | SIP/135 | | | 10 | 1567386039.11982 | 10 | | | P001 | 2019-09-02 09:00:50 |
| 41975 | 0 | 1567386095 | 1567386027.11981 | 4001 | COMPLETEAGENT | | SIP/135 | | | 10 | 46 | 1 | | | P001 | 2019-09-02 09:01:35 |
| 41976 | 0 | 1567386104 | 1567386092.11985 | 4003 | DID | | NONE | | | 63897815 | | | | | P001 | 2019-09-02 09:01:44 |
| 41977 | 0 | 1567386104 | 1567386092.11985 | 4003 | ENTERQUEUE | | NONE | | | | 63045831 | 1 | | | P001 | 2019-09-02 09:01:44 |
| 41978 | 0 | 1567386107 | 1567386095.11986 | 4004 | DID | | NONE | | | 63897817 | | | | | P001 | 2019-09-02 09:01:47 |
| 41979 | 0 | 1567386107 | 1567386095.11986 | 4004 | ENTERQUEUE | | NONE | | | | 67379922 | 1 | | | P001 | 2019-09-02 09:01:47 |
| 41980 | 0 | 1567386109 | 1567386092.11985 | 4003 | CONNECT | | Christine Nah | | | 5 | 1567386104.11987 | 4 | | | P001 | 2019-09-02 09:01:49 |
| 41981 | 0 | 1567386116 | 1567386095.11986 | 4004 | CONNECT | | Helen Ang | | | 9 | 1567386107.11990 | 9 | | | P001 | 2019-09-02 09:01:56 |
| 41982 | 0 | 1567386147 | 1567386095.11986 | 4004 | COMPLETEAGENT | | Helen Ang | | | 9 | 31 | 1 | | | P001 | 2019-09-02 09:02:27 |
| 41983 | 0 | 1567386155 | 1567386092.11985 | 4003 | COMPLETECALLER | | Christine Nah | | | 5 | 46 | 1 | | | P001 | 2019-09-02 09:02:35 |
| 41984 | 0 | 1567386254 | 1567386242.11999 | 4002 | DID | | NONE | | | 63897813 | | | | | P001 | 2019-09-02 09:04:14 |
| 41985 | 0 | 1567386254 | 1567386242.11999 | 4002 | ENTERQUEUE | | NONE | | | | 66438001 | 1 | | | P001 | 2019-09-02 09:04:14 |
| 41986 | 0 | 1567386255 | 1567386243.12000 | 4002 | DID | | NONE | | | 63897813 | | | | | P001 | 2019-09-02 09:04:15 |
| 41987 | 0 | 1567386255 | 1567386243.12000 | 4002 | ENTERQUEUE | | NONE | | | | 62168443 | 2 | | | P001 | 2019-09-02 09:04:15 |
| 41988 | 0 | 1567386266 | 1567386242.11999 | 4002 | CONNECT | | Catherine Chia | | | 12 | 1567386254.12001 | 12 | | | P001 | 2019-09-02 09:04:26 |
| 41989 | 0 | 1567386270 | 1567386243.12000 | 4002 | RINGNOANSWER | | Team 2 142 | | | 15000 | | | | | P001 | 2019-09-02 09:04:30 |
| 41990 | 0 | 1567386279 | 1567386243.12000 | 4002 | CONNECT | | Jace Yeo | | | 24 | 1567386275.12007 | 4 | | | P001 | 2019-09-02 09:04:39 |
| 41991 | 0 | 1567386292 | 1567386242.11999 | 4002 | COMPLETEAGENT | | Catherine Chia | | | 12 | 26 | 1 | | | P001 | 2019-09-02 09:04:52 |
+-------+-----+------------+------------------+-------+----------------+-----------+----------------+-------+------+----------+------------------+-------+-------+-------+-----------+---------------------+
$
and expected results here below
+------------------+----------+--------+-------+------+-------+
| call_id | did | status | queue | verb | agent |
+------------------+----------+--------+-------+------+-------+
| 1567386027.11981 | 63897811 | Missed | 4001 | DID | NULL |
| 1567386092.11985 | 63897815 | Missed | 4003 | DID | NULL |
| 1567386095.11986 | 63897817 | Missed | 4004 | DID | NULL |
| 1567386242.11999 | 63897813 | Missed | 4002 | DID | NULL |
| 1567386243.12000 | 63897813 | Missed | 4002 | DID | NULL |
| 1567386337.12010 | 63897813 | Missed | 4002 | DID | NULL |
+------------------+----------+--------+-------+------+-------+
【问题讨论】:
-
能否请您添加一些示例数据和您的预期输出
-
添加了样本数据及其结果。
-
Group by 旨在与聚合函数一起使用 - 您没有,因此结果可能不确定。请查看 dev.mysql.com/doc/refman/8.0/en/group-by-handling.html
-
为什么有从句 - 动词是否有可能不是规定的值?
-
为什么有连接时会错过 1567386027.11981?