我正在尝试按Campaign_id划分每个查询的总和。
例如,如果agent1
进入campaign_id
:505,进入Admin 1小时。 Agent1
也不会进入campaign_id
:两个小时。
这需要拆分,但显示Campaign_id
:3小时。
代码
set @fromDate = '2018-06-29 00:00:01';
set @ToDate = '2018-06-29 23:59:59';
SELECT full_name,
log.user,
log.campaign_id,
count(log.Status) as calls (sec_to_time(sum(pause_sec)+sum(wait_sec)+sum(talk_sec)+sum(dispo_sec)+sum(dead_sec))) as AgentTime,
(sec_to_time(sum(log.wait_sec))) as Wait,
(sec_to_time(sum(log.talk_sec))) as Talk,
(sec_to_time(sum(log.dispo_sec))) as Dispo,
(sec_to_time(sum(log.dead_sec))) as Dead,
(sec_to_time(sum(log.pause_sec))) as Pause,
Adminlog.Admin,
BreakLog.Break,
BUZZLog.BUZZ,
ITLog.IT,
LaggedLog.Lagged,
FROM Table1 as log
left join table2 as users
on log.user = users.user
left join (SELECT
user,
campaign_id,
(sec_to_time(sum(pause_sec))) as Admin
from Table1
where (sub_status='Admin')
and (event_time > @fromDate and event_time < @toDate)
group by user) as Adminlog
on log.user = Adminlog.user
left join (SELECT
user,
campaign_id,
(sec_to_time(sum(pause_sec))) as Break
from Table1
where (sub_status='Break')
and (event_time > @fromDate and event_time < @toDate)
group by user) as BreakLog
on log.user = BreakLog.user
left join (SELECT
user,
campaign_id,
(sec_to_time(sum(pause_sec))) as BUZZ
from Table1
where (sub_status='BUZZ')
and (event_time > @fromDate and event_time < @toDate)
group by user) as BUZZLog
on log.user = BUZZLog.user
left join (SELECT
user,
campaign_id,
(sec_to_time(sum(pause_sec))) as IT
from Table1
where (sub_status='IT')
and (event_time > @fromDate and event_time < @toDate)
group by user) as ITLog
on log.user = ITLog.user
left join (SELECT
user,
campaign_id,
(sec_to_time(sum(pause_sec))) as Lagged
from Table1
where (sub_status='Lagged')
and (event_time > @fromDate and event_time < @toDate)
group by user) as LaggedLog
on log.user = LaggedLog.user
where (log.event_time > @fromDate and event_time < @toDate)
group by campaign_id, user
结果
Full_name User Campaign_id Calls AgentTime ..... Admin
Agent1 101 505 2 01:01:23 01:54:57
Agent1 101 506 4 05:12:20 01:54:57
Agent1 101 507 22 00:21:36 01:54:57
在此示例中,我需要“管理员”以显示该广告系列的管理员时间。