码迷,mamicode.com
首页 > 数据库 > 详细

hive sql学习

时间:2019-10-31 21:51:22      阅读:94      评论:0      收藏:0      [点我收藏+]

标签:highlight   exp   tin   div   stat   att   regex   ddb   ret   

-- 转化占比  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

  

hive sql学习

标签:highlight   exp   tin   div   stat   att   regex   ddb   ret   

原文地址:https://www.cnblogs.com/manjianlei/p/11773786.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!