我正在获取支持数据。座席接听电话和聊天。所以我想计算聊天时间,但问题是一个座席一次可以进行多次聊天。如果我计算每个聊天的持续时间,那么它将提供更多的轮班时间。所以我想计算同时进行的聊天开始时间和最大聊天结束时间。
我发现了agentwise chat_id和并发聊天。但找不到聊天时间
from(
select *
from(select agent,
LEAD(agent,1) OVER (partition by agent ORDER BY chat_start) AS Lead_agent,
chat_id,chat_start,
LEAD(chat_start,1) OVER (partition by agent ORDER BY chat_start) AS Lead_chat_start,
chat_end,
lag(chat_end,1) OVER (partition by agent ORDER BY chat_start) AS Lag_chat_End
from(
select distinct SPLIT_PART(e.agent_id,'@',1) agent,ch.chat_id,
min(convert_timezone('GMT', 'GMT-5:30', (timestamp 'epoch' + e."timestamp" * interval '1 second'))) chat_start,
max(convert_timezone('GMT', 'GMT-5:30', (timestamp 'epoch' + e."timestamp" * interval '1 second'))) chat_end,
COUNT(case when user_type='agent' then 1 else null END ) Agent_Response
from livechat.chat_events e
join livechat.chats ch
on e.chat_id=ch.chat_id
join livechat.group_info g on e.chat_id=g.chat_id
where e."type"='message'
and user_type='agent'
and g.group_id in (1,4,7,19,21)
and cast(convert_timezone('GMT', 'GMT-5:30', (timestamp 'epoch' + ch.started_timestamp * interval '1 second')) as date) between '2019-06-01' and '2019-06-11'
group by 1,2
order by 1,3)
where (Agent_Response > 1)
) chat_diff) order by 1```
i expect output date, agent,chatid,chat_duration
Agent chat_id chat_start chat_end
elvin.m PSYONSZEGG 06-06-2019 22:30 06-06-2019 22:53
elvin.m PSXOOSY1MY 06-06-2019 22:21 06-06-2019 22:31
apoorva.ai PS3X6T7CXZ 11-06-2019 19:25 11-06-2019 19:34
apoorva.ai PS0X2S4JHG 11-06-2019 19:27 11-06-2019 19:40