【发布时间】:2021-03-03 07:47:53
【问题描述】:
卡莉德 |队列 |代理|率 |重新排队计数 :----- | :-------- | :---- | ---: | ------------: 122 | |奥尔加 | 空 | -1 123 | | | 空 | -1 124 |销售 | | 空 | 0 125 |服务 |汤姆 | 空 | 0 126 |销售 |颜 | 空 | 0 127 |销售 |金 | 空 | 0 127 |服务 |约翰 | 空 | 1 127 |评级 | | 4 | 2 128 |服务 |奥列格 | 空 | 0 128 |评级 | | 空 | 1 129 |服务 |约翰 | 空 | 0 130 |服务 |约翰 | 空 | 0 130 |评级 | | 2 | 1 131 |销售 |金 | 空 | 0 131 |服务 |奥列格 | 空 | 1 132 |服务 |奥列格 | 空 | 0 132 |评级 | | 5 | 1-- I'm trying to create a report for Call Center with quality rating system. -- Most of the calls are routed to the queues, where they wait to be answered by agents. -- When finishing the call, agent can hangup, requeue the call to another queue -- or requeue the call to the Rating queue, where caller may rate (or not) -- the quality of service (e.g. 1..5) -- There are also cases when calls are not answered, do not reach queue, etc. -- Below is a simplified example table. -- Requeued call keeps the same callid, but requeuecount is increased by 1.
队列 |代理| req2rating |收视率|平均评分 :-------- | :---- | ---------: | ------------: | ------------: 服务 |约翰 | 2 | 2 | 3 服务 |奥列格 | 2 | 1 | 5-- Those only agents who requeued calls to Rating queue. -- queue name, agent name, number of calls requeued to Rating, -- number of rated calls, average rating select cr.queue, cr.agent, count(cr.callid) as req2rating, count(cr1.rate) as ratingscount, avg(cr1.rate) as averagerating from callrecord cr inner join callrecord cr1 on cr.callid=cr1.callid and cr.requeuecount=cr1.requeuecount-1 and cr1.queue='Rating' group by cr.queue, cr.agent
队列 |代理|总通话 :-------- | :---- | ---------: | | 1 评级 | | 4 销售 | | 1 服务 |约翰 | 3 销售 |金 | 2 服务 |奥列格 | 3 |奥尔加 | 1 服务 |汤姆 | 1 销售 |颜 | 1-- All agents with their number of received calls. -- queue name, agent name, number of calls he have got select queue, agent, count(callid) as totalcalls from callrecord group by queue, agent
队列 |代理|总来电 | req2rating |收视率|平均评分 :-------- | :---- | ---------: | ---------: | ------------: | ------------: | | 1 | 空 | 空 | 空 评级 | | 4 | 空 | 空 | 空 销售 | | 1 | 空 | 空 | 空 服务 |约翰 | 3 | 2 | 2 | 3 销售 |金 | 2 | 空 | 空 | 空 服务 |奥列格 | 3 | 2 | 1 | 5 |奥尔加 | 1 | 空 | 空 | 空 服务 |汤姆 | 1 | 空 | 空 | 空 销售 |颜 | 1 | 空 | 空 | 空-- I want to combine the two above tables into one. -- Straightforward method, that works: select s1.queue, s1.agent, s1.totalcalls, s2.req2rating, s2.ratingscount, s2.averagerating from (select queue, agent, count(callid) as totalcalls from callrecord group by queue, agent) s1 left join (select cr.queue, cr.agent, count(cr.callid) as req2rating, count(cr1.rate) as ratingscount, avg(cr1.rate) as averagerating from callrecord cr inner join callrecord cr1 on cr.callid=cr1.callid and cr.requeuecount=cr1.requeuecount-1 and cr1.queue='Rating' group by cr.queue, cr.agent) s2 on s1.queue=s2.queue and s1.agent=s2.agent
-- Maybe there is a more clever and efficient way of doing this? -- I mean using only one select operand.
db小提琴here
【问题讨论】: