云管家跟进列表树状结构取数

时间:2020-04-22
本文章向大家介绍 云管家跟进列表树状结构取数,主要包括 云管家跟进列表树状结构取数使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

通过对相应的数值判断,获取对应的。

有空的时候进行学习

--odps sql 
--********************************************************************--
--description:云管家服务跟进记录明细表(JZSJZN-20628,分析师:何柏喜)
--author:shanwei
--create time:2020-04-20 16:43:34
--********************************************************************--
insert overwrite table a_jz_after_cloud_visit_record_detail

select
     rec.order_id    --订单ID
     ,rec.customer_passport_id --客户passort id
     ,ord.category_text as category_name --业务类型
     ,rec.create_time as record_create_time  --跟进创建时间
     ,ord.sign_pass_time   --审核通过单时间
     ,ord.city_name    --城市
     ,ord.audit_adviser_name as order_audit_adviser_name  --审核订单归属经纪人
     ,rec.creater_name as cloud_housekeeper_name  --管家姓名
     ,user.office_name as cloud_housekeepe_office_name  --云管家小组
     ,item.service_name as item_service_name  --服务项名称
     ,worker_num.order_worker_num   --订单劳动者数
     ,ord.status_text as order_status  --订单状态
     ,ord.sign_type_text as sign_type  --订单类型
     ,new_cpid.cpid as new_worker_cpid --(最新)劳动者id
     ,worker.real_name as new_worker_name  --(最新)劳动者姓名
     ,ord.appointment_begin_date
     ,ord.appointment_end_date
     ,item.service_days
     ,item.service_end_time
     ,item.service_begin_time
     ,ord.cancel_submit_time
     ,ord.cancel_pass_time
     ,case
         when rec.service_target_type = 1 then '客户'
         when rec.service_target_type = 2 then '商家'
         else rec.service_target_type
       end as service_target_type  --服务对象类型
     ,rec.service_type  --服务类型
     ,rec_lab.service_lable_name  --服务标签
     ,rec_lab.service_parent_lable_name1  --服务标签父级节点1
     ,rec_lab.service_parent_lable_name2  --服务标签父级节点2
     ,rec_lab.service_parent_lable_name3  --服务标签父级节点3
     ,rec_lab.service_parent_lable_name4  --服务标签父级节点4
     ,rec_lab.service_parent_lable_name5  --服务标签父级节点5
     ,rec_lab.service_parent_lable_name6  --服务标签父级节点6
     ,rec.service_description   --服务描述
from f_jz_after_service_visit_record rec
left join f_jz_order_common ord
       on rec.order_id = ord.id
left join f_jz_order_item item
       on rec.order_item_id = item.id
left join (
          select
               order_id,count(distinct cpid) as order_worker_num
          from f_jz_order_item
          group by order_id
          ) worker_num
       on rec.order_id = worker_num.order_id
left join (
          select
               order_id,cpid
          from (
               select
                    order_id,cpid
                    ,row_number() over(partition by order_id order by item_create_time desc) as desc_num
               from f_jz_order_item
               ) t
          where desc_num = 1
          ) new_cpid
       on rec.order_id = new_cpid.order_id
left join f_jz_worker_info worker
       on new_cpid.cpid = worker.cpassportid
left join d_sys_user user
       on rec.creater_id = user.id
left join (
          select
               t1.id,t2.lable_name as service_lable_name
               ,if(t2.parent_lable_name6 is not null
                   ,t2.parent_lable_name6
                   ,if(t2.parent_lable_name5 is not null
                       ,t2.parent_lable_name5
                       ,if(t2.parent_lable_name4 is not null
                           ,t2.parent_lable_name4
                           ,if(t2.parent_lable_name3 is not null
                               ,t2.parent_lable_name3
                               ,if(t2.parent_lable_name2 is not null
                                   ,t2.parent_lable_name2
                                   ,t2.parent_lable_name1))))) as service_parent_lable_name1
                                   
               ,if(t2.parent_lable_name6 is not null and t2.parent_lable_name5 is not null
                   ,t2.parent_lable_name5
                   ,if(t2.parent_lable_name5 is not null and t2.parent_lable_name4 is not null
                       ,t2.parent_lable_name4
                       ,if(t2.parent_lable_name4 is not null and t2.parent_lable_name3 is not null
                           ,t2.parent_lable_name3
                           ,if(t2.parent_lable_name3 is not null and t2.parent_lable_name2 is not null
                               ,t2.parent_lable_name2
                               ,if(t2.parent_lable_name2 is not null and t2.parent_lable_name1 is not null
                                   ,t2.parent_lable_name1
                                   ,null))))) as service_parent_lable_name2
               
               ,if(t2.parent_lable_name6 is not null and t2.parent_lable_name5 is not null and t2.parent_lable_name4 is not null
                   ,t2.parent_lable_name4
                   ,if(t2.parent_lable_name5 is not null and t2.parent_lable_name4 is not null and t2.parent_lable_name3 is not null
                       ,t2.parent_lable_name3
                       ,if(t2.parent_lable_name4 is not null and t2.parent_lable_name3 is not null  and t2.parent_lable_name2 is not null
                           ,t2.parent_lable_name2
                           ,if(t2.parent_lable_name3 is not null and t2.parent_lable_name2 is not null and t2.parent_lable_name1 is not null
                               ,t2.parent_lable_name1
                               ,null)))) as service_parent_lable_name3
               
               ,if(t2.parent_lable_name6 is not null and t2.parent_lable_name5 is not null and t2.parent_lable_name4 is not null and t2.parent_lable_name3 is not null
                   ,t2.parent_lable_name3
                   ,if(t2.parent_lable_name5 is not null and t2.parent_lable_name4 is not null and t2.parent_lable_name3 is not null and t2.parent_lable_name2 is not null
                       ,t2.parent_lable_name2
                       ,if(t2.parent_lable_name4 is not null and t2.parent_lable_name3 is not null  and t2.parent_lable_name2 is not null and t2.parent_lable_name1 is not null
                           ,t2.parent_lable_name1
                               ,null))) as service_parent_lable_name4
               
               ,if(t2.parent_lable_name6 is not null and t2.parent_lable_name5 is not null and t2.parent_lable_name4 is not null and t2.parent_lable_name3 is not null and t2.parent_lable_name2 is not null
                   ,t2.parent_lable_name2
                   ,if(t2.parent_lable_name5 is not null and t2.parent_lable_name4 is not null and t2.parent_lable_name3 is not null and t2.parent_lable_name2 is not null and t2.parent_lable_name1 is not null
                       ,t2.parent_lable_name1
                       ,null)) as service_parent_lable_name5
               
               ,if(t2.parent_lable_name6 is not null and t2.parent_lable_name5 is not null and t2.parent_lable_name4 is not null and t2.parent_lable_name3 is not null and t2.parent_lable_name2 is not null and t2.parent_lable_name1 is not null
                   ,t2.parent_lable_name1
                   ,null) as service_parent_lable_name6
          from (
               select
                    id,service_lable
               from f_jz_after_service_visit_record
               lateral view explode(split(service_lables,',')) b as service_lable
               ) t1
          left join f_jz_after_lables t2
                 on t1.service_lable = cast(t2.id as string)
          ) rec_lab
       on rec.id = rec_lab.id
;

原文地址:https://www.cnblogs.com/sakura3/p/12751777.html