Professional Documents
Culture Documents
Docum 2
Docum 2
Docum 2
shopee_seller_cs_case_db__enquiry_tab__my_continuous_s0_live as t2
on t1.case_id = t2.case_id
on case_tab.case_id = t1.case_id
where t1.inbound_type = 1 -- IB
-- and t1.is_first_in_case = 1
and t2.inbound_type = 2 -- OB
-- and t1.channel_type = 3
and t1.case_id != 0
group by t1.case_id
and MIN(t2.ctime) - MIN(t1.ctime) < 60*60*24*7 --limit for data mart look back period to find
reply
and MIN(t2.ctime) - MIN(t1.ctime) > 0 --to exclude cases where OB came first (else
response time will be neg)
),
reply_time_metric_webform as
,MIN(t1.ctime) as incoming_time
,MIN(t2.ctime) as first_reply_sent_time
from chatbot_data.shopee_seller_cs_case_db__enquiry_tab__my_continuous_s0_live as t1
on t1.case_id = t2.case_id
on case_tab.case_id = t1.case_id
where t1.inbound_type = 1 -- IB
-- and t1.is_first_in_case = 1
and t2.inbound_type = 2 -- OB
-- and t1.channel_type = 3
and t1.case_id != 0
group by t1.case_id
and MIN(t2.ctime) - MIN(t1.ctime) < 60*60*24*7 --limit for data mart look back period to find
reply
and MIN(t2.ctime) - MIN(t1.ctime) > 0 --to exclude cases where OB came first (else
response time will be neg)
),
reply_time_metric as
(
union
),
special_form_tab as
select enquiry_tab.case_id
from chatbot_data.shopee_seller_cs_form_db__form_submission_tab__my_continuous_s0_live
as form_submission_tab
-- to get form_type --
on form_tab.id = form_submission_tab.form_id
-- to get case_id --
group by enquiry_tab.case_id
case_table as
select case_tab.case_id
,case_tab.user_id as cs_user_id
,case_related_attr_tab.user_type
,case_tab.channel_type
,case_tab.owner_id
,case_tab.enquiry_config_id
,reason_view.l1_name
,reason_view.l2_name
,reason_view.l3_name
-- to get user_type --
left join
chatbot_data.shopee_seller_cs_case_db__case_related_attr_tab__my_continuous_s0_live as
case_related_attr_tab
on case_tab.case_id = case_related_attr_tab.case_id
-- to get RCs --
on case_tab.enquiry_config_id = reason_view.l3_id
),
agent_admin as
select account_id
,agent_name
,agent_email
,agent_owner_team
,company_name
,reporting_manager_email
from regops_cs.dim_agent_my_agent_admin_snapshot_di_live
),
queue_table as
,queue_name
,owner_id as queue_owner_id
from chatbot_data.shopee_seller_cs_routing_db__queue_tab__my_continuous_s0_live
and status_flag = 1
),
queue_owner as
,agent_type_name as queue_owner_team
from chatbot_data.shopee_seller_cs_account_db__agent_type_tab__my_continuous_s0_live
and status_flag = 1
),
init_owner as
select case_id
,initial_owner_id
from regops_cs.dwd_rep_my_cs_kpi_shopee_case_initial_owner_di_live
),
initial_owner as
select case_table.case_id
from case_table
on case_table.case_id = init_owner.case_id
),
initial_owner_details as
select case_id
,agent_name as initial_owner_agent_name
,agent_email as initial_owner_agent_email
,agent_owner_team as initial_owner_agent_owner_team
from initial_owner
select
reply_table.case_id
,reply_table.incoming_time
,cast(from_unixtime(reply_table.incoming_time, '${MY_TZ}') as timestamp) as
incoming_time_datetime
,reply_table.first_reply_sent_time
,case_table.owner_id
,agent_admin.agent_name
,agent_admin.agent_email
,agent_admin.agent_owner_team
,agent_admin.company_name as agent_company
,agent_admin.reporting_manager_email
,queue_table.queue_name
,queue_owner.queue_owner_team
,coalesce(agent_admin.agent_owner_team, queue_owner.queue_owner_team) as
case_owner_team
,case_table.owner_type as case_owner_type
,initial_owner_details.initial_owner_id
,initial_owner_details.initial_owner_agent_name
,initial_owner_details.initial_owner_agent_email
,initial_owner_details.initial_owner_agent_owner_team
,case_table.cs_user_id
,case_table.user_type
,case_table.channel_type
,case_table.channel
,case_table.enquiry_config_id
,case_table.l1_name
,case_table.l2_name
,case_table.l3_name
,COALESCE(special_form_tab.special_form_count, 0) as special_form_count
,${L1D_Date} report_date
,'${UDF_REGION}' grass_region
on reply_table.case_id = special_form_tab.case_id
on reply_table.case_id = case_table.case_id
on case_table.owner_id = agent_admin.account_id
on case_table.owner_id = queue_table.queue_id
on queue_table.queue_owner_id = queue_owner.queue_owner_id
on case_table.case_id = initial_owner_details.case_id