-- 转化占比 tmk约课和总的约课在最近两个月的转化人数 select on_where, count(distinct T.fk_student) as subscribe_num_1, count(distinct if(is_attend=1,fk_student,null)) attend_num_1, count(distinct if(is_attend=1 and course_start_time<pay_end_time,stu_id,null)) zjk_num_1 from( select * from ( select fk_student,course_start_time,on_where, if(goto_class_time!='0' and is_replay!=1,1,null) is_attend from dwddb.dwd_mkt_experience_class_detail where course_start_time>="2019-08-30" AND course_start_time<=current_date() and status = 1 and dp = 'active' and on_where =2) as b left join (select stu_id,pay_end_time from dwddb.dwd_trd_sales_stu_all_v1 where pay_end_time>="2019-08-30" and pay_end_time <= current_date() and course_type_first_id = 1 and return_type = 1 and stu_type_v1 !=6 and dt=regexp_replace(date_sub(current_date(),1),"-","") ) a on a.stu_id = b.fk_student where pay_end_time BETWEEN course_start_time and DATE_add(course_start_time, 15) ) T group by on_where