-- insert overwrite ads_fineReport.ads_Student_service_analysis selectdistinct t1.*,dc.className,dc1.className, cast(now() as string) as data_created_time from (select dsc.studentId,du.userYoulunum ,dsc.userId ,cla.className,
dcc.custName,dsc.projectId ,pro.projectName,pro2.projectId, pro2.projectName ,dssp.dptId ,dd.dpt_n1,dd.dpt_n2,dssp.schoolId,
dbsa.school_name ,dbsa.area_id ,dbsa.area_name as onedpt_name,dbsa.region_id ,dbsa.region_name ,ds.subjectId ,ds.subjectName ,dsc.studentclassYear ,
dsc.studentclassOpendate ,dsc.studentclassExpiredate ,
dssp.studentprojectLmuserid ,ee.userName ,dsc.studentclassOpenstatus ,dsc.studentclassBizsrctype ,
dsc.studentclassOrderno,dsc.studentclassCategory,doc.coType ,doc.coSubtype ,doa.agreementStatus , doa.agreementUserinfoconfirmstatus,
dsb.bill_no ,dsg.goods_name ,dsb.bill_post_status,dsb.bill_send_date,dsb.bill_apply_date ,
if(dsb.bill_class_id like'%,%',split_part(dsb.bill_class_id,',',1),dsb.bill_class_id ) as bill_class_id_one ,
split_part(dsb.bill_class_id,',',2) as bill_class_id_two
from datawarehouse.dwd_bd_BdStudentclass dsc
leftjoin datawarehouse.dwd_ss_SsStudentproject dssp on dsc.userId = dssp.studentUserid and dsc.projectId = dssp.projectId
leftjoin datawarehouse.dwd_bd_BdEe de on dssp.studentprojectLmuserid = de.userId and de.eeAvlstatus='Y'AND de.userId <>''leftjoin datawarehouse.dwd_bd_BdDptee dde on dde.eeId = de.eeId and dde.dptEerelation ='P'AND dde.eeId <>''leftjoin datawarehouse.dwd_uc_UcUser du on dsc.userId = du.userId AND du.userId <>''leftjoin datawarehouse.dwd_bd_BdClass cla on dsc.classId = cla.classId AND cla.classId <>''LEFTJOIN (select dbd.dpt_id as dptId , dbd.dpt_n1, dbd.dpt_n2 from dws.dws_bd_Dpt dbd) dd
ON dd.dptId = dde.dptId AND dd.dptId <>''leftjoin dws.dws_bd_SchoolArea dbsa on dssp.schoolId = dbsa.school_id
leftjoin datawarehouse.dwd_bd_BdProject pro on dsc.projectId = pro.projectId AND pro.projectId <>''LEFTJOIN datawarehouse.dwd_bd_BdProject pro2 ONsubstring(pro.projectLevelcode,1,10) = pro2.projectLevelcode AND pro2.projectLevelcode <>''leftjoin datawarehouse.dwd_bd_BdSubject ds on cla.subjectId = ds.subjectId AND ds.subjectId <>''leftjoin datawarehouse.dwd_bd_BdEe ee on dssp.studentprojectLmuserid = ee.userId AND ee.userId <>''leftjoin datawarehouse.dwd_oc_OcOrder doo on doo.userId = dsc.userId and doo.orderNo = dsc.studentclassOrderno AND doo.userId <>''AND doo.orderNo <>''leftjoin datawarehouse.dwd_oc_OcAgreement doa on doo.orderId = doa.orderId
leftjoin datawarehouse.dwd_oc_OcClassorder doc on doc.orderId = doo.orderId AND doc.orderId <>''leftjoin dwd.dwd_st_bill dsb on dsb.bill_apply_user = dsc.userId
leftjoin dwd.dwd_st_bill_dtl dsbd on dsb.bill_id = dsbd.bill_id
leftjoin dwd.dwd_st_goods dsg on dsbd.goods_id = dsg.goods_id
leftjoin datawarehouse.dwd_ct_CtCust dcc on dcc.userId = dsc.userId and dcc.custDelstatus ='N'AND dcc.userId <>''where dsc.studentclassBizsrctype ='O'and dsc.studentclassOpenstatus in ('O','P')
groupby dsc.studentId ,du.userYoulunum ,dsc.userId ,cla.className,dcc.custName,dsc.projectId ,pro.projectName,
pro2.projectId, pro2.projectName ,dssp.dptId ,dd.dpt_n1,dd.dpt_n2,dssp.schoolId,
dbsa.school_name ,dbsa.area_id ,dbsa.area_name ,dbsa.region_id ,dbsa.region_name ,ds.subjectId ,ds.subjectName ,dsc.studentclassYear ,
dsc.studentclassOpendate ,dsc.studentclassExpiredate,
dssp.studentprojectLmuserid ,ee.userName ,dsc.studentclassOpenstatus ,dsc.studentclassBizsrctype,
dsc.studentclassOrderno ,dsc.studentclassCategory ,doc.coType ,doc.coSubtype ,doa.agreementStatus , doa.agreementUserinfoconfirmstatus,
dsb.bill_no ,dsg.goods_name ,dsb.bill_post_status,dsb.bill_send_date,dsb.bill_apply_date ,
if(dsb.bill_class_id like'%,%',split_part(dsb.bill_class_id,',',1),dsb.bill_class_id ),
split_part(dsb.bill_class_id,',',2))t1
leftjoin datawarehouse.dwd_bd_BdClass dc on t1.bill_class_id_one = dc.classId AND dc.classId <>''leftjoin datawarehouse.dwd_bd_BdClass dc1 on t1.bill_class_id_two = dc1.classId AND dc1.classId <>'';
最新 优化后SQL 语句
-- insert overwrite ads_fineReport.ads_Student_service_analysis select dsc.studentId,du.userYoulunum ,dsc.userId ,cla.className, dcc.custName,
dsc.projectId ,dbpi.project_name_two ,dbpi.project_id_one , dbpi.project_name_one ,dbed.dpt_id_two ,dbed.dpt_name_two as dpt_n1,dbed.dpt_n2 ,dssp.schoolId,dbsa.school_name ,
dbsa.area_id ,dbsa.area_name as onedpt_name,dbsa.region_id ,dbsa.region_name ,ds.subjectId ,ds.subjectName ,dsc.studentclassYear ,dsc.studentclassOpendate ,
dsc.studentclassExpiredate , dssp.studentprojectLmuserid ,dbed.user_name ,dsc.studentclassOpenstatus ,dsc.studentclassBizsrctype ,dsc.studentclassOrderno,
dsc.studentclassCategory,doc.coType ,doc.coSubtype ,doa.agreementStatus , doa.agreementUserinfoconfirmstatus,dssbg.bill_no ,dssbg.goods_name ,
dssbg.bill_post_status,dssbg.bill_send_date,dssbg.bill_apply_date , dssbg.bill_class_id_one , dssbg.bill_class_id_two ,dc.className ,dc1.className,
cast(now() as string) as data_created_time
from datawarehouse.dwd_bd_BdStudentclass dsc
leftjoin datawarehouse.dwd_ss_SsStudentproject dssp on dsc.userId = dssp.studentUserid and dsc.projectId = dssp.projectId
leftjoin dws.dws_bd_EeDpt dbed on dssp.studentprojectLmuserid = dbed.user_id
leftjoin datawarehouse.dwd_uc_UcUser du on dsc.userId = du.userId
leftjoin datawarehouse.dwd_bd_BdClass cla on dsc.classId = cla.classId
leftjoin dws.dws_bd_SchoolArea dbsa on dssp.schoolId = dbsa.school_id
leftjoin dws.dws_bd_ProjectInfo dbpi on dsc.projectId = dbpi.project_id_two
leftjoin datawarehouse.dwd_bd_BdSubject ds on cla.subjectId = ds.subjectId
leftjoin datawarehouse.dwd_oc_OcOrder doo on doo.userId = dsc.userId and doo.orderNo = dsc.studentclassOrderno AND doo.userId <>''AND doo.orderNo <>''leftjoin datawarehouse.dwd_oc_OcAgreement doa on doo.orderId = doa.orderId
leftjoin datawarehouse.dwd_oc_OcClassorder doc on doc.orderId = doo.orderId
leftjoin dws.dws_st_StBillGoods dssbg on dsc.userId = dssbg.bill_apply_user
leftjoin datawarehouse.dwd_bd_BdClass dc on dssbg.bill_class_id_one = dc.classId
leftjoin datawarehouse.dwd_bd_BdClass dc1 on dssbg.bill_class_id_two = dc1.classId
leftjoin datawarehouse.dwd_ct_CtCust dcc on dcc.userId = dsc.userId and dcc.custDelstatus ='N'AND dcc.userId <>''where dsc.studentclassBizsrctype ='O'and dsc.studentclassOpenstatus in ('O','P')
groupby dsc.studentId ,du.userYoulunum ,dsc.userId ,cla.className,dcc.custName,dsc.projectId ,dbpi.project_name_two ,dbpi.project_id_one , dbpi.project_name_one ,
dbed.dpt_id_two ,dbed.dpt_name_two,dbed.dpt_n2,dssp.schoolId,dbsa.school_name ,dbsa.area_id ,dbsa.area_name ,dbsa.region_id ,dbsa.region_name , ds.subjectId ,ds.subjectName ,
dsc.studentclassYear ,dsc.studentclassOpendate ,dsc.studentclassExpiredate, dssp.studentprojectLmuserid ,dbed.user_name ,dsc.studentclassOpenstatus , dsc.studentclassBizsrctype,
dsc.studentclassOrderno ,dsc.studentclassCategory , doc.coType ,doc.coSubtype ,doa.agreementStatus , doa.agreementUserinfoconfirmstatus, dssbg.bill_no ,dssbg.goods_name ,
dssbg.bill_post_status,dssbg.bill_send_date,dssbg.bill_apply_date ,dssbg.bill_class_id_one , dssbg.bill_class_id_two ,dc.className ,dc1.className
[2]sql优化-ads_fineReport.ads_employee_intention
原始SQL 语句
insert overwrite ads_fineReport.ads_employee_intention
selectdistinct dcci.custId ,t1.custId as gencustId,dcci.custCreateddate ,dcci.brandId ,dcci.custprojDelstatus ,dcci.custType ,dcci.custprojCommtime ,
dcci.custprojIntention ,dcci.projectId as oneprojectId ,pro.projectName as oneprojectName ,pro2.projectId ,pro2.projectName ,
dcci.custprojSourcechannel ,ori.originName as oneoriginName
,ori2.originId ,ori2.originName ,dcci.custprojOwner ,
de.userName ,dde.dptId as usedptId ,casewhen t8_2.dpt_n1 isnullthen'其他'else t8_2.dpt_n1 endas dpt_n1,
casewhen t8_2.dpt_n2 isnullthen'其他'else t8_2.dpt_n2 endas dpt_n2 ,dbsa.school_id ,dbsa.school_name as aadptName ,dbsa.area_id ,dbsa.area_name ,dbsa.region_id ,dbsa.region_name ,
dcci.custprojCommid , casewhen tp.status isnulland dcci.custType ='S'then'非正价课'else tp.status endas status ,cast(now() as string) as data_created_time
from
datawarehouse.dwd_ct_CtCustindex dcci
leftjoin datawarehouse.dwd_bd_BdProject pro ON dcci.projectId = pro.projectId and pro.projectAvlstatus ='Y'and pro.projectDelstatus ='N'leftjoin datawarehouse.dwd_bd_BdProject pro2 onsubstring(pro.projectLevelcode,1,10)=pro2.projectLevelcode
leftjoin datawarehouse.dwd_es_BdOrigin ori on ori.originId = dcci.custprojSourcechannel
leftjoin datawarehouse.dwd_es_BdOrigin ori2 onsubstring(ori.originLevelcode,1,10) = ori2.originLevelcode
leftjoin datawarehouse.dwd_bd_BdEe de on de.userId = dcci.custprojOwner
leftjoin datawarehouse.dwd_bd_BdDptee dde on de.eeId = dde.eeId and dde.dpteeRelation ='P'LEFTJOIN (select dbd.dpt_id as dptId , dbd.dpt_n1, dbd.dpt_n2 from dws.dws_bd_Dpt dbd) t8_2 ON t8_2.dptId = dde.dptId
leftjoin dws.dws_bd_SchoolArea dbsa on dbsa.school_id = dcci.custprojschool
leftjoin (
selectdistinct h.custId, aa.status from datawarehouse.dwd_oc_OcOrder o
join(
selectdistinct oi.orderId ,'正价课'as status from datawarehouse.dwd_oc_OcOrderitem oi
leftjoin datawarehouse.dwd_bd_BdClass cl on oi.skuId = cl.classId
leftjoin datawarehouse.dwd_bd_BdClasstype cltype on cl.classtypeId = cltype.classtypeId
where cltype.classtypeUsesourcetype ='E'
) aa on o.orderId = aa.orderId
join datawarehouse.dwd_oc_OcClassorder dooc on o.orderId = dooc.orderId
join datawarehouse.dwd_oc_CtCust a on a.userId =o.userId
leftjoin datawarehouse.dwd_ct_CtCust h on a.custId = h.custId
where h.custType ='S'and h.custDelstatus ='N'unionallselectdistinct h.custId, aa.status from datawarehouse.dwd_oc_OcOrder o
join(
selectdistinct oi.orderId ,'非正价课'as status from datawarehouse.dwd_oc_OcOrderitem oi
leftjoin datawarehouse.dwd_bd_BdClass cl on oi.skuId = cl.classId
leftjoin datawarehouse.dwd_bd_BdClasstype cltype on cl.classtypeId = cltype.classtypeId
where cltype.classtypeUsesourcetype <>'E'
) aa on o.orderId = aa.orderId
join datawarehouse.dwd_oc_OcClassorder doc on o.orderId = doc.orderId
join datawarehouse.dwd_oc_CtCust a on a.userId =o.userId
leftjoin datawarehouse.dwd_ct_CtCust h on a.custId = h.custId
where h.custType ='S'and h.custDelstatus ='N'and h.custId notin (
selectdistinct h.custId from datawarehouse.dwd_oc_OcOrder o
join(
selectdistinct oi.orderId ,'正价课'as status from datawarehouse.dwd_oc_OcOrderitem oi
leftjoin datawarehouse.dwd_bd_BdClass cl on oi.skuId = cl.classId
leftjoin datawarehouse.dwd_bd_BdClasstype cltype on cl.classtypeId = cltype.classtypeId
where cltype.classtypeUsesourcetype ='E'
) aa on o.orderId = aa.orderId
join datawarehouse.dwd_oc_OcClassorder dooc on o.orderId = dooc.orderId
join datawarehouse.dwd_oc_CtCust a on a.userId =o.userId
leftjoin datawarehouse.dwd_ct_CtCust h on a.custId = h.custId
where h.custType ='S'and h.custDelstatus ='N'
)
) tp on tp.custId = dcci.custId
leftjoin (
selectdistinct custId from datawarehouse.dwd_ct_CtCustindex where custType ='C'and custId notin (
selectdistinct dccc.custId from datawarehouse.dwd_ct_CtComm dccc
)
) t1 on t1.custId = dcci.custId
where dcci.custprojDelstatus ='N'and dcci.custStatus ='N'and dcci.custmarketingtype ='T'and dcci.brandid ='YOULU';
最新 优化后SQL 语句
-- insert overwrite ads_fineReport.ads_employee_intention select dcci.custId ,t1.custId as gencustId,dcci.custCreateddate ,dcci.brandId ,dcci.custprojDelstatus ,dcci.custType ,dcci.custprojCommtime ,
dcci.custprojIntention ,dcci.projectId , dbpi.project_name_two , dbpi.project_id_one , dbpi.project_name_one , dcci.custprojSourcechannel ,
deco.origin_name_two ,deco.origin_id_one ,deco.origin_name_one ,dcci.custprojOwner , dbed.user_name ,dbed.dpt_id_two as usedptId ,
casewhen dbed.dpt_name_two isnullthen'其他'else dbed.dpt_name_two endas dpt_n1, casewhen dbed.dpt_n2 isnullthen'其他'else dbed.dpt_n2 endas dpt_n2 ,
dbsa.school_id ,dbsa.school_name as aadptName ,dbsa.area_id ,dbsa.area_name ,dbsa.region_id ,dbsa.region_name , dcci.custprojCommid ,
casewhen dccs.status isnulland dcci.custType ='S'then'非正价课'else dccs.status endas status ,cast(now() as string) as data_created_time
from
datawarehouse.dwd_ct_CtCustindex dcci
leftjoin dws.dws_bd_ProjectInfo dbpi on dcci.projectId = dbpi.project_id_two
leftjoin dws.dws_es_ClueOrigin deco on dcci.custprojSourcechannel = deco.origin_id_two
leftjoin dws.dws_bd_EeDpt dbed on dcci.custprojOwner = dbed.user_id
leftjoin dws.dws_bd_SchoolArea dbsa on dbsa.school_id = dcci.custprojschool
leftjoin ads_fineReport.dws_ct_CustStatus dccs on dccs.custId = dcci.custId
leftjoin (selectdistinct custId from datawarehouse.dwd_ct_CtCustindex where custType ='C'and custId notin (selectdistinct dccc.custId from datawarehouse.dwd_ct_CtComm dccc)) t1 on t1.custId = dcci.custId
where dcci.custprojDelstatus ='N'and dcci.custStatus ='N'and dcci.custmarketingtype ='T'and dcci.brandid ='YOULU'groupby dcci.custId, t1.custId, dcci.custCreateddate ,dcci.brandId ,dcci.custprojDelstatus ,dcci.custType ,dcci.custprojCommtime ,
dcci.custprojIntention ,dcci.projectId , dbpi.project_name_two , dbpi.project_id_one , dbpi.project_name_one , dcci.custprojSourcechannel ,
deco.origin_name_two ,deco.origin_id_one ,deco.origin_name_one ,dcci.custprojOwner , dbed.user_name ,dbed.dpt_id_two , dbed.dpt_name_two , dbed.dpt_n2,
dbsa.school_id ,dbsa.school_name ,dbsa.area_id ,dbsa.area_name ,dbsa.region_id ,dbsa.region_name , dcci.custprojCommid ,
casewhen dccs.status isnulland dcci.custType ='S'then'非正价课'else dccs.status end-- 客户是否正价课-- insert overwrite ads_fineReport.dws_ct_CustStatuswith cust_status as (
selectDISTINCT dccc.custId , dbbc2.classtypeUsesourcetype
from datawarehouse.dwd_oc_OcOrder dooo
join datawarehouse.dwd_oc_OcOrderitem dooo2 on dooo.orderId = dooo2.orderId
join datawarehouse.dwd_oc_OcClassorder dooc on dooo.orderId = dooc.orderId
join datawarehouse.dwd_oc_CtCust docc on dooo.userId = docc.userId and dooo.userId <>''leftjoin datawarehouse.dwd_ct_CtCust dccc on docc.custId = dccc.custId
leftjoin datawarehouse.dwd_bd_BdClass dbbc on dooo2.skuId = dbbc.classId
leftjoin datawarehouse.dwd_bd_BdClasstype dbbc2 on dbbc.classtypeId = dbbc2.classtypeId
where dccc.custType ='S'and dccc.custDelstatus ='N'
)
selectDISTINCT cs.custId , '正价课'as status, cast(now() as string) as data_created_time
from cust_status cs
where cs.classtypeUsesourcetype ='E'unionallselectDISTINCT cs.custId , '非正价课'as status, cast(now() as string) as data_created_time
from cust_status cs
where cs.classtypeUsesourcetype <>'E'and cs.custId notin ( selectDISTINCT cs.custId from cust_status cs where cs.classtypeUsesourcetype ='E')
[3]sql优化-ads_fineReport.channel_extension_report
原始SQL 语句
-- insert overwrite ads_fineReport.channel_extension_report SELECT
t1.cust_id,
t1.cust_created_date,
substring(t1.cust_created_date,1,10) as analysis_date,
concat(substring(cust_created_date,12,2),':00') as analysis_hour,
if(t1.clue_es_ee_id isnull,'未知',t1.clue_es_ee_id) as clue_es_ee_id,
if(t1.ee_name isnull,'未知',t1.ee_name) as ee_name,
if(t1.clue_dpt_id isnull,'未知',t1.clue_dpt_id) as clue_dpt_id,
if(t1.clue_dpt_name isnull,'未知',t1.clue_dpt_name) as clue_dpt_name,
if(t8.user_name isnull,'未知',t8.user_name) as user_name_f,
if(t3.school_id isnull,'未知',t3.school_id) as school_id_f,
if(t3.schoolName isnull,'未知',t3.schoolName) as schoolName_f,
if(t3.area_id isnull,'未知',t3.area_id) as area_id_f,
if(t3.areaName isnull,'未知',t3.areaName) as areaName_f,
if(t4.school_id isnull,'未知',t4.school_id) as school_id_c,
if(t4.schoolName isnull,'未知',t4.schoolName) as schoolName_c,
if(t4.area_id isnull,'未知',t4.area_id) as area_id_c,
if(t4.areaName isnull,'未知',t4.areaName) as areaName_c,
if(t1.originid1 isnull,'未知',t1.originid1) as originid1,
if(t1.originid2 isnull,'未知',t1.originid2) as originid2,
if(t1.projectid1 isnull,'未知',t1.projectid1) as projectid1,
if(t1.projectid2 isnull,'未知',t1.projectid2) as projectid2,
if(t1.originname1 isnull,'未知',t1.originname1) as originname1,
if(t1.originname2 isnull,'未知',t1.originname2) as originname2,
if(t1.projectname1 isnull,'未知',t1.projectname1) as projectname1,
if(t1.projectname2 isnull,'未知',t1.projectname2) as projectname2,
if(t7.class_sale_status ='Y','正价课业绩','非正价课业绩') as achieve_type,
t6.receipt_created_date,
datediff(t6.receipt_created_date,t1.cust_created_date) as day_diff,
casewhen t5.ai_approval_status in ('PAS','PRE','PEN','PRO','PTP') and t5.ait_approval_node ='SF'and t5.ait_approval_action ='FOR'and t6.receipt_type ='I'and t6.receipt_pay_status ='PAI'then'正业绩'when t6.receipt_type ='E'then'负业绩'elsenullendas receiptAmount_type,
t5.order_id,
t6.receipt_amount,
t6.receipt_id,
casewhen t2.comm_status in ('N','Y','A') then'正常沟通'when t2.comm_status in ('E') then'空号'when t2.comm_status in ('B','U','X') then'未接听秒挂'when t2.comm_status in ('S') then'停机'elsenullendas comm_status,
casewhen t2.intention ='A1'then'首访未接'when t2.intention ='A'then'意向强烈'when t2.intention ='B'then'较强意向'when t2.intention ='C'then'一般意向'elsenullendas intention,
cast(now() as string) as data_created_time
FROM (
SELECT ct.custId as cust_id,ct.userId as user_id,clue_info.clueEseeid as clue_es_ee_id,ee.userName as ee_name,clue_info.clueEsdptid as clue_dpt_id,dic.origindictName as clue_dpt_name,ct.custCreateddate as cust_created_date,
ori.one_origin_id as originid1,ori.one_origin_name as originname1,ori.two_origin_id as originid2,ori.two_origin_name as originname2,pro.two_project_id as projectid2,pro.two_project_name as projectname2,
pro.one_project_id as projectid1,pro.one_project_name as projectname1,c.custProjSchool as cust_proj_school
FROM (
SELECT*FROM datawarehouse.dwd_ct_CtCust
WHERE custAvlstatus ='Y'AND custDelstatus ='N'AND custCreateddate >= DATE_SUB(now(),INTERVAL12MONTH)
) ct
INNERJOIN datawarehouse.dwd_ct_CtCustproj c ON ct.custId = c.custId
LEFTJOIN (
select a.originId as two_origin_id,a.originName as two_origin_name,b.originId as one_origin_id,b.originName as one_origin_name
from datawarehouse.dwd_es_BdOrigin a
leftjoin datawarehouse.dwd_es_BdOrigin b onsubstring(a.originLevelcode,1,10) = b.originLevelcode
groupby a.originId,a.originName,b.originId,b.originName
) ori ON ct.custSourceChannel = ori.two_origin_id
LEFTJOIN (
select a.projectId as two_project_id,a.projectName as two_project_name,b.projectId as one_project_id,b.projectName as one_project_name
from datawarehouse.dwd_bd_BdProject a
leftjoin datawarehouse.dwd_bd_BdProject b onsubstring(a.projectLevelcode,1,10) = b.projectLevelcode
groupby a.projectId,a.projectName,b.projectId,b.projectName
) pro ON ct.custInitProject = pro.two_project_id
LEFTJOIN (
select custId as cust_id,clueSourceid as clue_source_id
FROM (
SELECT*,row_number() over(partitionby custId orderby clueSourcetime) as rnk
FROM datawarehouse.dwd_ct_CtClue
WHERE clueDelStatus ='N'AND clueCategory ='A'AND clueSourcetime >= DATE_SUB(now(),INTERVAL12MONTH)
) r
WHERE rnk =1
) clue ON ct.custId = clue.cust_id
LEFTJOIN datawarehouse.dwd_es_clueeslog clue_info ON clue.clue_source_id = clue_info.clueId
LEFTJOIN (
SELECT*FROM datawarehouse.dwd_es_BdOrigindict
WHERE origindictAvlstatus ='Y'AND origindictDelstatus ='N'
) dic ON clue_info.clueEsdptid = dic.origindictId
LEFTJOIN (
select a.eeId as ee_id, a.eeNo, a.userId, a.userName, a.schoolId, a.eePostype, b.dptId, b.posId, b.dpteeRelation, b.dpteeSourceid
from datawarehouse.dwd_bd_BdEe a
leftjoin datawarehouse.dwd_bd_BdDptee b on a.eeId = b.eeId
) ee ON clue_info.clueEseeid = ee.ee_id
) t1
LEFTJOIN (
SELECT cust_id,comm_owner,comm_school,intention,comm_status
FROM (
SELECT custId as cust_id,commOwner as comm_owner,commSchool as comm_school,commStatus as comm_status,intention,commTime as comm_time,row_number() over(partitionby custId orderby commTime) as rnk
FROM (
select a.commprojId, a.custId, a.projectId, a.commTime, b.commcreatedDate, a.commprojcreatedDate, a.commprojIntention intention,
a.commprojdelStatus, a.commprojgradeStatus, b.commId, b.commContent, b.commStatus, b.commOwner, b.commWay, b.commSchool
from datawarehouse.dwd_ct_CtCommproj a leftjoin datawarehouse.dwd_ct_CtComm b on a.commId = b.commId
where a.commTime >= DATE_SUB(now(),INTERVAL12MONTH)
) r -- 沟通表WHERE commprojdelStatus ='N'and commTime <>'2000-01-01'
) t WHERE t.rnk =1
) t2 ON t1.cust_id = t2.cust_id
leftjoin (
select dbsa.school_id,dbsa.school_name as schoolName,dbsa.area_id ,dbsa.area_name as areaName from dws.dws_bd_SchoolArea dbsa
) t3 ON t2.comm_school = t3.school_id
leftjoin (
select dbsa.school_id,dbsa.school_name as schoolName,dbsa.area_id ,dbsa.area_name as areaName from dws.dws_bd_SchoolArea dbsa
) t4 ON t1.cust_proj_school = t4.school_id
LEFTJOIN (
SELECT a.user_id,a.order_id,a.order_total_amount,a.ai_approval_status,b.aitApprovalnode as ait_approval_node,b.aitApprovalAction as ait_approval_action
FROM (
select o.orderId as order_id, o.userId as user_id, o.orderTotalamount*0.01as order_total_amount, o.orderAvlStatus as order_avl_status,
o.orderDelStatus as order_del_status, app.aiApprovalStatus as ai_approval_status, app.aiId as ai_id
from datawarehouse.dwd_oc_OcOrder o
leftjoin datawarehouse.dwd_oc_OcApprovalinfo app on o.aiId = app.aiId
) a
LEFTJOIN datawarehouse.dwd_oc_OcApprovalitem b ON a.ai_id = b.aiId
WHERE a.user_id <>''AND a.order_avl_status ='Y'AND a.order_del_status ='N'AND a.ai_approval_status IN ('PAS','PRE','PEN','PRO','PTP')
AND b.aitApprovalNode ='SF'AND b.aitApprovalAction ='FOR'
) t5 ON t1.user_id = t5.user_id
LEFTJOIN (
SELECT orderId as order_id,receiptTradedate as receipt_created_date,receiptAmount as receipt_amount,receiptType as receipt_type,receiptId as receipt_id,receiptPayStatus as receipt_pay_status
FROM datawarehouse.dwd_oc_OcReceipt -- 收据表WHERE receiptDelStatus ='N'AND receiptRealStatus ='Y'AND receiptType in ('I','E')
) t6 ON t5.order_id = t6.order_id
LEFTJOIN (
SELECT orderId as order_id,'Y'as class_sale_status
FROM datawarehouse.dwd_oc_OcOrderitem a -- 订单项表LEFTJOIN datawarehouse.dwd_bd_BdClass b ON a.skuId = b.classId -- 班级表WHERE classAvlStatus ='Y'AND classDelStatus ='N'AND classSaleStatus ='Y'
) t7 ON t5.order_id = t7.order_id
LEFTJOIN (
SELECTdistinct user_id,user_name
FROM (
select a.userId as user_id, a.userName as user_name, b.dpteeRelation
from datawarehouse.dwd_bd_BdEe a
leftjoin datawarehouse.dwd_bd_BdDptee b on a.eeId = b.eeId
) r
WHERE dpteeRelation ='P'
) t8 ON t2.comm_owner = t8.user_id
groupby
t1.cust_id,t1.cust_created_date,substring(t1.cust_created_date,1,10),concat(substring(cust_created_date,12,2),':00'),
if(t1.clue_es_ee_id isnull,'未知',t1.clue_es_ee_id),if(t1.ee_name isnull,'未知',t1.ee_name),if(t1.clue_dpt_id isnull,'未知',t1.clue_dpt_id),
if(t1.clue_dpt_name isnull,'未知',t1.clue_dpt_name),if(t8.user_name isnull,'未知',t8.user_name),if(t3.school_id isnull,'未知',t3.school_id),
if(t3.schoolName isnull,'未知',t3.schoolName),if(t3.area_id isnull,'未知',t3.area_id),if(t3.areaName isnull,'未知',t3.areaName),
if(t4.school_id isnull,'未知',t4.school_id),if(t4.schoolName isnull,'未知',t4.schoolName),if(t4.area_id isnull,'未知',t4.area_id),
if(t4.areaName isnull,'未知',t4.areaName),if(t1.originid1 isnull,'未知',t1.originid1),if(t1.originid2 isnull,'未知',t1.originid2),
if(t1.projectid1 isnull,'未知',t1.projectid1),if(t1.projectid2 isnull,'未知',t1.projectid2),
if(t1.originname1 isnull,'未知',t1.originname1),if(t1.originname2 isnull,'未知',t1.originname2),if(t1.projectname1 isnull,'未知',t1.projectname1),
if(t1.projectname2 isnull,'未知',t1.projectname2),if(t7.class_sale_status ='Y','正价课业绩','非正价课业绩'),
t6.receipt_created_date,datediff(t6.receipt_created_date,t1.cust_created_date),casewhen t5.ai_approval_status in ('PAS','PRE','PEN','PRO','PTP') and t5.ait_approval_node ='SF'and t5.ait_approval_action ='FOR'and t6.receipt_type ='I'and t6.receipt_pay_status ='PAI'then'正业绩'when t6.receipt_type ='E'then'负业绩'elsenullend,
t5.order_id,t6.receipt_amount,t6.receipt_id,
casewhen t2.comm_status in ('N','Y','A') then'正常沟通'when t2.comm_status in ('E') then'空号'when t2.comm_status in ('B','U','X') then'未接听秒挂'when t2.comm_status in ('S') then'停机'elsenullend,
casewhen t2.intention ='A1'then'首访未接'when t2.intention ='A'then'意向强烈'when t2.intention ='B'then'较强意向'when t2.intention ='C'then'一般意向'elsenullend,cast(now() as string);
最新 优化后SQL 语句
insert overwrite ads_fineReport.channel_extension_report
select t1.cust_id,t1.cust_created_date,substring(t1.cust_created_date,1,10) as analysis_date,
concat(substring(cust_created_date,12,2),':00') as analysis_hour,
if(t1.clue_es_ee_id isnull,'未知',t1.clue_es_ee_id) as clue_es_ee_id,
if(t1.ee_name isnull,'未知',t1.ee_name) as ee_name,
if(t1.clue_dpt_id isnull,'未知',t1.clue_dpt_id) as clue_dpt_id,
if(t1.clue_dpt_name isnull,'未知',t1.clue_dpt_name) as clue_dpt_name,
if(t8.userName isnull,'未知',t8.userName) as user_name_f,
if(t3.school_id isnull,'未知',t3.school_id) as school_id_f,
if(t3.school_name isnull,'未知',t3.school_name) as schoolName_f,
if(t3.area_id isnull,'未知',t3.area_id) as area_id_f,
if(t3.area_name isnull,'未知',t3.area_name) as areaName_f,
if(t4.school_id isnull,'未知',t4.school_id) as school_id_c,
if(t4.school_name isnull,'未知',t4.school_name) as schoolName_c,
if(t4.area_id isnull,'未知',t4.area_id) as area_id_c,
if(t4.area_name isnull,'未知',t4.area_name) as areaName_c,
if(t1.originid1 isnull,'未知',t1.originid1) as originid1,
if(t1.originid2 isnull,'未知',t1.originid2) as originid2,
if(t1.projectid1 isnull,'未知',t1.projectid1) as projectid1,
if(t1.projectid2 isnull,'未知',t1.projectid2) as projectid2,
if(t1.originname1 isnull,'未知',t1.originname1) as originname1,
if(t1.originname2 isnull,'未知',t1.originname2) as originname2,
if(t1.projectname1 isnull,'未知',t1.projectname1) as projectname1,
if(t1.projectname2 isnull,'未知',t1.projectname2) as projectname2,
if(t5.class_sale_status ='Y','正价课业绩','非正价课业绩') as achieve_type,
t5.receipt_created_date,
datediff(t5.receipt_created_date,t1.cust_created_date) as day_diff,
t5.receiptAmount_type,
t5.order_id,
t5.receipt_amount,
t5.receipt_id,
casewhen t2.comm_status in ('N','Y','A') then'正常沟通'when t2.comm_status in ('E') then'空号'when t2.comm_status in ('B','U','X') then'未接听秒挂'when t2.comm_status in ('S') then'停机'elsenullendas comm_status,
casewhen t2.intention ='A1'then'首访未接'when t2.intention ='A'then'意向强烈'when t2.intention ='B'then'较强意向'when t2.intention ='C'then'一般意向'elsenullendas intention,
cast(now() as string) as data_created_time
from ads_fineReport.dws_channel_extension_report_cust t1
leftjoin (
select cust_id,comm_owner,comm_school,intention,comm_status
from (
select a.custId as cust_id, b.commOwner as comm_owner, b.commSchool as comm_school, b.commStatus as comm_status, a.commprojIntention as intention,
row_number() over(partitionby a.custId orderby a.commTime) as rnk
from datawarehouse.dwd_ct_CtCommproj a
leftjoin datawarehouse.dwd_ct_CtComm b on a.commId = b.commId
where a.commprojDelstatus ='N'and a.commTime >= DATE_SUB(now(),INTERVAL12MONTH)
) t where t.rnk =1
) t2 ON t1.cust_id = t2.cust_id
leftjoin dws.dws_bd_SchoolArea t3 on t2.comm_school = t3.school_id
leftjoin dws.dws_bd_SchoolArea t4 on t1.cust_proj_school = t4.school_id
leftjoin ads_fineReport.dws_channel_extension_report_receipt t5 on t1.user_id = t5.user_id
leftjoin datawarehouse.dwd_bd_BdEe t8 on t2.comm_owner = t8.userId
groupby t1.cust_id,t1.cust_created_date,substring(t1.cust_created_date,1,10),
concat(substring(cust_created_date,12,2),':00'),if(t1.clue_es_ee_id isnull,'未知',t1.clue_es_ee_id),if(t1.ee_name isnull,'未知',t1.ee_name),
if(t1.clue_dpt_id isnull,'未知',t1.clue_dpt_id),if(t1.clue_dpt_name isnull,'未知',t1.clue_dpt_name),if(t8.userName isnull,'未知',t8.userName),
if(t3.school_id isnull,'未知',t3.school_id),if(t3.school_name isnull,'未知',t3.school_name),if(t3.area_id isnull,'未知',t3.area_id),
if(t3.area_name isnull,'未知',t3.area_name),if(t4.school_id isnull,'未知',t4.school_id),if(t4.school_name isnull,'未知',t4.school_name),
if(t4.area_id isnull,'未知',t4.area_id),if(t4.area_name isnull,'未知',t4.area_name),if(t1.originid1 isnull,'未知',t1.originid1),
if(t1.originid2 isnull,'未知',t1.originid2),if(t1.projectid1 isnull,'未知',t1.projectid1),if(t1.projectid2 isnull,'未知',t1.projectid2),
if(t1.originname1 isnull,'未知',t1.originname1),if(t1.originname2 isnull,'未知',t1.originname2),if(t1.projectname1 isnull,'未知',t1.projectname1),
if(t1.projectname2 isnull,'未知',t1.projectname2),if(t5.class_sale_status ='Y','正价课业绩','非正价课业绩'),t5.receipt_created_date,
datediff(t5.receipt_created_date,t1.cust_created_date),t5.receiptAmount_type,t5.order_id,t5.receipt_amount,t5.receipt_id,
casewhen t2.comm_status in ('N','Y','A') then'正常沟通'when t2.comm_status in ('E') then'空号'when t2.comm_status in ('B','U','X') then'未接听秒挂'when t2.comm_status in ('S') then'停机'elsenullend,
casewhen t2.intention ='A1'then'首访未接'when t2.intention ='A'then'意向强烈'when t2.intention ='B'then'较强意向'when t2.intention ='C'then'一般意向'elsenullend-- ------------------------------------ insert overwrite ads_fineReport.dws_channel_extension_report_custselect dccc.custId as cust_id, dccc.userId as user_id ,dccc.custCreateddate as cust_created_date,
dccc2.custprojSchool as cust_proj_school,
deco.origin_id_one as originid1, deco.origin_name_one as originname1, deco.origin_id_two as originid2, deco.origin_name_two as originname2,
dbpi.project_id_two as projectid2, dbpi.project_name_two as projectname2,dbpi.project_id_one as projectid1,dbpi.project_name_one as projectname1,
dec2.clueEseeid as clue_es_ee_id, dec2.clueEsdptid as clue_dpt_id,
debo.origindictName as clue_dpt_name,
dbbe.userName as ee_name,
cast(now() as string) as data_created_time
from datawarehouse.dwd_ct_CtCust dccc
join datawarehouse.dwd_ct_CtCustproj dccc2 on dccc.custId = dccc2.custId
leftjoin dws.dws_es_ClueOrigin deco on dccc.custSourcechannel = deco.origin_id_two
leftjoin dws.dws_bd_ProjectInfo dbpi on dccc.custInitproject = dbpi.project_id_two
leftjoin (
select custId as cust_id,clueSourceid as clue_source_id
from (
select custId ,clueSourceid ,row_number() over(partitionby custId orderby clueSourcetime) as rnk
from datawarehouse.dwd_ct_CtClue
where clueDelStatus ='N'and clueCategory ='A'AND clueSourcetime >= DATE_SUB(now(),INTERVAL12MONTH)
) r
where rnk =1
) clue on dccc.custId = clue.cust_id
leftjoin datawarehouse.dwd_es_clueeslog dec2 on clue.clue_source_id = dec2.clueId
leftjoin datawarehouse.dwd_es_BdOrigindict debo on dec2.clueEsdptid = debo.origindictId
leftjoin datawarehouse.dwd_bd_BdEe dbbe on dec2.clueEseeid = dbbe.eeId
where dccc.custAvlstatus ='Y'and dccc.custDelstatus ='N'and dccc.custCreateddate >= DATE_SUB(now(),INTERVAL12MONTH);
-- ----------------------------------- insert overwrite ads_fineReport.dws_channel_extension_report_receiptselect dooo.userId as user_id, dooo.orderId as order_id,
casewhen door.receiptType ='I'and door.receiptPayStatus ='PAI'then'正业绩'when door.receiptType ='E'then'负业绩'elsenullendas receiptAmount_type,
door.receiptTradedate as receipt_created_date, door.receiptAmount as receipt_amount, door.receiptType as receipt_type, door.receiptId as receipt_id,
door.receiptPayStatus as receipt_pay_status, temp.class_sale_status, cast(now() as string) as data_created_time
from datawarehouse.dwd_oc_OcOrder dooo
leftjoin datawarehouse.dwd_oc_OcApprovalinfo dooa on dooo.aiId = dooa.aiId
leftjoin datawarehouse.dwd_oc_OcApprovalitem dooa2 on dooa.aiId = dooa2.aiId
leftjoin datawarehouse.dwd_oc_OcReceipt door on dooo.orderId = door.orderId and door.receiptDelStatus ='N'and door.receiptRealStatus ='Y'and door.receiptType in ('I','E')
leftjoin (
select dooo2.orderId as order_id, 'Y'as class_sale_status
from datawarehouse.dwd_oc_OcOrderitem dooo2
leftjoin datawarehouse.dwd_bd_BdClass dbbc on dooo2.skuId = dbbc.classId
where dbbc.classAvlstatus ='Y'and dbbc.classDelstatus ='N'and dbbc.classSalestatus ='Y'
) temp on dooo.orderId = temp.order_id
where dooo.userId <>''and dooo.orderAvlstatus ='Y'and dooo.orderDelstatus ='N'and dooa.aiApprovalstatus in ('PAS','PRE','PEN','PRO','PTP')
and dooa2.aitApprovalNode ='SF'and dooa2.aitApprovalaction ='FOR'
-- insert overwrite ads_fineReport.ads_operation_follow_analysis SELECT a.custCreateddate,a.custId,a.projectid,pro2.projectName as custinitprojectname,pro2.projectLevelcode as custinitprojectlevelcode,pro3.projectId as Projectcollegeid,
pro3.projectName as Projectcollegename,pro3.projectLevelcode as Projectcollegelevelcode,comm.comm_time,a.custProjOwner as Custprojowner,ee.UserName,dd.dptId,dd.dpt_n1,dd.dpt_n2,
proj.custProjschool AS Custprojschool,dbsa.school_name as Custprojschoolname,dbsa.area_id as Custprojarea, dbsa.area_name as Custprojareaname,comm.comm_time ,a.custprojSourcechannel as custsourcechannel2,
ori.originName as custsourcechannelname2,ori2.originId as custsourcechannel,ori2.originName as custsourcechannelname,comm.commProjIntention,comm.commContent,comm.commStatus,
comm.commOwner,comm.userName,comm.schoolId,comm.school_name,t2.clueResultowner,t2.userName,t2.schoolId,t2.schoolname, cast(now() as string) as data_created_time
from(
select commTime,projectid,custId,custCreateddate,custProjOwner,custDelstatus ,custprojSourcechannel
from(
select* ,row_number() over(partitionby custId,projectid orderby commTime desc) num
from (
select b.commTime,c.projectid,c.custId,c.custCreateddate,c.custProjOwner,c.custDelstatus,c.custprojSourcechannel
from datawarehouse.dwd_ct_CtCommproj b
rightjoin (
select h.custInitproject projectid,a.custId,a.custCreateddate,
a.custProjOwner,a.custProjDelstatus as custDelstatus,
h.custSourcechannel custprojSourcechannel
from datawarehouse.dwd_ct_CtCustindex a
leftjoin datawarehouse.dwd_ct_CtCust h on a.custId = h.custId AND h.custId <>''where a.custCreateddate >= date_add(now(), interval-2month)
) c
on b.custId=c.custId and b.projectId=c.projectid
)A
)as b
where b.num =1groupby commTime,projectid,custId,custCreateddate,custProjOwner,custDelstatus ,custprojSourcechannel
)a
leftjoin datawarehouse.dwd_bd_BdProject pro2 on a.projectid=pro2.projectId AND pro2.projectId <>''leftjoin datawarehouse.dwd_bd_BdProject pro3 onsubstring(pro2.projectLevelcode,1,10)=pro3.projectLevelcode AND pro3.projectLevelcode <>''leftjoin datawarehouse.dwd_bd_BdEe ee on a.custProjOwner=ee.userId AND ee.userId <>''leftjoin datawarehouse.dwd_bd_BdDptee dde on ee.eeId = dde.eeId and dde.dptEerelation ='P'LEFTJOIN (select dbd.dpt_id as dptId , dbd.dpt_n1, dbd.dpt_n2 from dws.dws_bd_Dpt dbd) dd
ON dd.dptId = dde.dptId AND dd.dptId <>''leftjoin datawarehouse.dwd_ct_CtCustproj proj on a.custId = proj.custId and a.projectid = proj.projectId AND proj.custId <>''AND proj.projectId <>''leftjoin dws.dws_bd_SchoolArea dbsa on proj.custProjschool = dbsa.school_id
leftjoin (
select*from (
select c.custId,b.projectId,c.custProjCommtime,b.commProjIntention,
a.commContent,a.commStatus,b.commOwner,
casewhen b.commTime isnullor b.commTime =''then c.custProjCommtime
else b.commTime endas comm_time,
ee.userName, ee.schoolId,dpt.dptName school_name,
row_number()over(partitionby c.custId,b.projectId orderby b.commTime) as num
from (select*from datawarehouse.dwd_ct_CtCommproj where commTime isnotnull) b
join (select*from datawarehouse.dwd_ct_CtCustindex where custCreateddate >= date_add(now(), interval-2month)) c on b.custId=c.custId and b.projectId=c.projectId
leftjoin datawarehouse.dwd_ct_CtComm a on a.commId = b.commId AND a.commId <>''leftjoin datawarehouse.dwd_bd_BdEe ee on b.commOwner=ee.userId AND ee.userId <>''leftjoin datawarehouse.dwd_bd_BdDpt dpt on ee.schoolId = dpt.dptRelationid AND dpt.dptRelationid <>''
) co
where co.num=1
)comm on a.custId=comm.custId and a.projectid=comm.projectId AND comm.custId <>''AND comm.projectId <>''leftjoin datawarehouse.dwd_es_BdOrigin ori on a.custprojSourcechannel=ori.originId AND ori.originId <>''leftjoin datawarehouse.dwd_es_BdOrigin ori2 onsubstring(ori.originLevelcode,1,10)=ori2.originLevelcode AND ori2.originLevelcode <>''leftjoin (
select f.custId,f.clueResultowner,ee.userName, ee.schoolId,dpt.dptName schoolname
from(
select custId,clueResultowner,row_number() over(partitionby custId orderby clueCreateddate asc) num
from datawarehouse.dwd_ct_CtClue
) as f
leftjoin datawarehouse.dwd_bd_BdEe ee on f.clueResultowner=ee.userId AND ee.userId <>''leftjoin datawarehouse.dwd_bd_BdDpt dpt on ee.schoolId = dpt.dptRelationid AND dpt.dptRelationid <>''where f.num =1
) t2 on a.custId = t2.custId AND t2.custId <>''where proj.custProjdelstatus='N'groupby a.custId,a.custCreateddate,a.projectid,pro2.projectName,pro2.projectLevelcode,pro3.projectId,pro3.projectName,pro3.projectLevelcode,comm.comm_time,a.custProjOwner,ee.UserName,dd.dptId,
dd.dpt_n1,dd.dpt_n2,proj.custProjschool,dbsa.school_name ,dbsa.area_id ,dbsa.area_name ,comm.comm_time,a.custprojSourcechannel,ori.originName,ori2.originId,ori2.originName,comm.commProjIntention,
comm.commContent,comm.commStatus,comm.commOwner,comm.userName, comm.schoolId,comm.school_name,t2.clueResultowner,t2.userName,t2.schoolId,t2.schoolname;
最新 优化后SQL 语句
-- insert overwrite ads_fineReport.ads_operation_follow_analysis SELECT
a.cust_created_date ,a.cust_id ,a.project_id ,dbpi.project_name_two as custinitprojectname,dbpi.project_level_code_two as custinitprojectlevelcode,dbpi.project_id_one as Projectcollegeid,
dbpi.project_name_one as Projectcollegename,dbpi.project_level_code_one as Projectcollegelevelcode,a.comm_time ,a.cust_proj_owner as Custprojowner, dbed.user_name ,dbed.dpt_id_two ,
dbed.dpt_name_two as dpt_n1, dbed.dpt_n2 ,proj.custProjschool AS Custprojschool,dbsa.school_name as Custprojschoolname,dbsa.area_id as Custprojarea, dbsa.area_name as Custprojareaname,dbsa.region_id ,
dbsa.region_name ,a.custproj_commtime,a.cust_sourcechannel as custsourcechannel2,deco.origin_name_two as custsourcechannelname2,deco.origin_id_one as custsourcechannel,
deco.origin_name_two as custsourcechannelname,a.commproj_intention ,a.comm_content ,a.comm_status ,a.comm_owner ,a.user_name ,a.school_id ,a.school_name ,dcccf.clue_resultowner ,
dcccf.user_name ,dcccf.school_id ,dcccf.school_name , cast(now() as string) as data_created_time
from ads_fineReport.dws_operation_follow_analysis_comm a
leftjoin dws.dws_bd_ProjectInfo dbpi on a.project_id = dbpi.project_id_two
leftjoin dws.dws_bd_EeDpt dbed on a.cust_proj_owner = dbed.user_id
leftjoin dws.dws_es_ClueOrigin deco on a.cust_sourcechannel = deco.origin_id_two
leftjoin dws.dws_ct_CustClue_First dcccf on a.cust_id = dcccf.cust_id
leftjoin datawarehouse.dwd_ct_CtCustproj proj on a.cust_id = proj.custId and a.project_id = proj.projectId
leftjoin dws.dws_bd_SchoolArea dbsa on proj.custProjschool = dbsa.school_id
where proj.custProjdelstatus='N'AND proj.custId <>''AND proj.projectId <>''groupby a.cust_created_date ,a.cust_id ,a.project_id ,dbpi.project_name_two ,dbpi.project_level_code_two ,dbpi.project_id_one ,
dbpi.project_name_one ,dbpi.project_level_code_one ,a.comm_time ,a.cust_proj_owner ,dbed.user_name ,dbed.dpt_id_two ,dbed.dpt_name_two ,dbed.dpt_n2 ,
proj.custProjschool ,dbsa.school_name,dbsa.area_id , dbsa.area_name ,dbsa.region_id ,dbsa.region_name ,a.custproj_commtime,a.cust_sourcechannel,
deco.origin_name_two,deco.origin_id_one,deco.origin_name_two,a.commproj_intention ,a.comm_content ,a.comm_status ,a.comm_owner ,a.user_name ,
a.school_id ,a.school_name ,dcccf.clue_resultowner ,dcccf.user_name ,dcccf.school_id ,dcccf.school_name;
-- --------------------- 客户首次线索归属信息-- insert overwrite dws.dws_ct_CustClue_Firstselect temp_1.custId, temp_1.clueResultowner, dbbe.userName, dbbe.schoolId, dbbd.dptName as schoolName, cast(now() as string) as data_created_time
from (
select custId,clueResultowner from (
select custId,clueResultowner,row_number() over(partitionby custId orderby clueCreateddate asc) ranks
from datawarehouse.dwd_ct_CtClue dccc where clueDelstatus ='N'and isPhysicsDel =2
) temp where temp.ranks =1
)temp_1
leftjoin datawarehouse.dwd_bd_BdEe dbbe on temp_1.clueResultowner=dbbe.userId
leftjoin datawarehouse.dwd_bd_BdDpt dbbd on dbbe.schoolId = dbbd.dptRelationid
where temp_1.custId <>'';
-- --------------------- 客户首次沟通信息-- insert overwrite ads_fineReport.dws_operation_follow_analysis_comm select a.cust_id , a.cust_created_date , a.project_id , a.cust_proj_owner , a.cust_sourcechannel ,
comm.comm_time,comm.custprojCommtime , comm.commprojIntention , comm.commContent , comm.commStatus , comm.commOwner , comm.userName , comm.schoolId , comm.school_name ,
cast(now() as string) as data_created_time
from(
select comm_time, project_id, cust_id, cust_created_date, cust_proj_owner, cust_sourcechannel
from (
select dccc3.commTime as comm_time ,temp.project_id ,temp.cust_id ,temp.cust_created_date ,temp.cust_proj_owner ,temp.cust_sourcechannel,
row_number() over(partitionby temp.cust_id ,temp.project_id orderby dccc3.commTime desc) num
from datawarehouse.dwd_ct_CtCommproj dccc3
rightjoin (
select dccc.custId as cust_id ,dccc.custCreateddate as cust_created_date ,dccc.custProjOwner as cust_proj_owner,
dccc2.custSourcechannel as cust_sourcechannel, dccc2.custInitproject as project_id
from datawarehouse.dwd_ct_CtCustindex dccc
leftjoin datawarehouse.dwd_ct_CtCust dccc2 on dccc.custId = dccc2.custId
where dccc.custCreateddate >= date_add(now(), interval-2month)
) temp on dccc3.custId=temp.cust_id and dccc3.projectId=temp.project_id
)as b where b.num =1
)a
leftjoin (
select custId, projectId, custprojCommtime, commprojIntention, commContent, commStatus, commOwner, comm_time, userName, schoolId, school_name
from (
select dccc2.custId ,dccc.projectId ,dccc2.custprojCommtime , dccc.commprojIntention , dccc3.commContent , dccc3.commStatus , dccc.commOwner ,
dccc.commTime as comm_time, dbbe.userName , dbbe.schoolId , dbbd.dptName as school_name,
row_number()over(partitionby dccc2.custId, dccc.projectId orderby dccc.commTime) as num
from datawarehouse.dwd_ct_CtCommproj dccc
join datawarehouse.dwd_ct_CtCustindex dccc2 on dccc.custId = dccc2.custId and dccc.projectId = dccc2.projectId
leftjoin datawarehouse.dwd_ct_CtComm dccc3 on dccc.commId = dccc3.commId
leftjoin datawarehouse.dwd_bd_BdEe dbbe on dccc.commOwner = dbbe.userId
leftjoin datawarehouse.dwd_bd_BdDpt dbbd on dbbe.schoolId = dbbd.dptRelationid and dbbd.dptRelationid <>''where dccc2.custCreateddate >= date_add(now(), interval-2month)
) co where co.num =1
)comm on a.cust_id=comm.custId and a.project_id=comm.projectId AND comm.projectId <>'';
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!