Hive 算两时间差

hive算时间差:CAST((unix_timestamp(process_dttm) - unix_timestamp(pay_dttm)) / 60 AS int)>10

-- 需求人:林楚君 (Ashley) 
-- 最近分区为全量数据


insert overwrite table dw_busdb.busticket_issue_successrate_and_timely_rate partition (d='${pre_day}')



select 
a.date
,a.failticket_order_cnt
-- ,b.successticket_order_cnt
,c.allticket_order_cnt - a.failticket_order_cnt as successticket_order_cnt
,c.allticket_order_cnt
,concat(cast(nvl((c.allticket_order_cnt - a.failticket_order_cnt )*100,0)/c.allticket_order_cnt as decimal(10,2)),'%') as success_order_rate


,immedi.whithin10min_order_cnt
,immedi.over10min_order_cnt
,immedi.all_nonappoint_order_cnt
,immedi.10min_order_rate

from 
(
      select  to_date(process_dttm) as date 
      ,count(distinct order_number) failticket_order_cnt
        FROM dw_busdb.tbl_order o
        WHERE o.d = '${pre_day}'
            AND process_dttm >= '2018-01-01'  --'${pre_day}'
            AND process_dttm < '${cur_day}'
            AND o.order_business_type = 'bus'
            and order_channel='ctrip' 
            and utm_source not like "ctripwx%"
            and utm_source not like "wxscan%" 
            and utm_source not like "ticketmachine%"
            and utm_source not like "tmv2%" 
            and utm_source not like "busweixin%" 
            and utm_source not like "offzhcz%"
            and process_state>5 and user_cancel=0  -- 出票失败
		group by to_date(process_dttm)	 			 
)a
left join 
(
      select  to_date(process_dttm) as date 
      ,count(distinct order_number) successticket_order_cnt
        FROM dw_busdb.tbl_order o
        WHERE o.d = '${pre_day}'
            AND process_dttm >=  '2018-01-01'  --'${pre_day}'
            AND process_dttm <  '${cur_day}'
            AND o.order_business_type = 'bus'
            and order_channel='ctrip' 
            and utm_source not like "ctripwx%"
            and utm_source not like "wxscan%" 
            and utm_source not like "ticketmachine%"
            and utm_source not like "tmv2%" 
            and utm_source not like "busweixin%" 
            and utm_source not like "offzhcz%"
            and process_state = 5  -- 出票成功
		group by to_date(process_dttm)	 
)b

on a.date = b.date


left join 
(
      select   to_date(process_dttm) as date
      ,count(distinct order_number) allticket_order_cnt
        FROM dw_busdb.tbl_order o
        WHERE o.d ='${pre_day}'
            AND process_dttm >= '2018-01-01'  --'${pre_day}'
            AND process_dttm <  '${cur_day}'
            AND o.order_business_type = 'bus'
            and order_channel='ctrip' 
            and utm_source not like "ctripwx%"
            and utm_source not like "wxscan%" 
            and utm_source not like "ticketmachine%"
            and utm_source not like "tmv2%" 
            and utm_source not like "busweixin%" 
            and utm_source not like "offzhcz%"
            and process_state>4 and user_cancel=0  -- 参与出票订单总量
			group by to_date(process_dttm)				
)c
on a.date = c.date

left join

(
        select a.date
		,a.whithin10min_order_cnt
        ,b.over10min_order_cnt
        ,c.all_nonappoint_order_cnt
        ,concat(cast(nvl(a.whithin10min_order_cnt*100,0)/c.all_nonappoint_order_cnt as decimal(10,2)),'%') as 10min_order_rate
        from 
        (
              select to_date(process_dttm) as date 
              ,count(distinct order_number) whithin10min_order_cnt
                FROM dw_busdb.tbl_order o
                WHERE o.d = '${pre_day}'
                    AND process_dttm >= '2018-01-01'  --'${pre_day}'
                    AND process_dttm < '${cur_day}'
                    AND o.order_business_type = 'bus'
                    and order_channel='ctrip' 
                    and utm_source not like "ctripwx%"
                    and utm_source not like "wxscan%" 
                    and utm_source not like "ticketmachine%"
                    and utm_source not like "tmv2%" 
                    and utm_source not like "busweixin%" 
                    and utm_source not like "offzhcz%"
                    and booking_flag in  (0,2)
                    and process_state>4 and  user_cancel=0
                    and CAST((unix_timestamp(process_dttm) - unix_timestamp(pay_dttm)) / 60 AS int)<=10
				group by to_date(process_dttm)	
        )a
        left join 
        (
              select  to_date(process_dttm) as date 
              ,count(distinct order_number) over10min_order_cnt
                FROM dw_busdb.tbl_order o
                WHERE o.d = '${pre_day}'
                    AND process_dttm >= '2018-01-01'  --'${pre_day}'
                    AND process_dttm <  '${cur_day}'
                    AND o.order_business_type = 'bus'
                    and order_channel='ctrip' 
                    and utm_source not like "ctripwx%"
                    and utm_source not like "wxscan%" 
                    and utm_source not like "ticketmachine%"
                    and utm_source not like "tmv2%" 
                    and utm_source not like "busweixin%" 
                    and utm_source not like "offzhcz%"
                    and booking_flag in (0,2)
                    and process_state>4 and  user_cancel=0
                    and CAST((unix_timestamp(process_dttm) - unix_timestamp(pay_dttm)) / 60 AS int)>10
				group by to_date(process_dttm)	
        )b
        on a.date = b.date
        left join 
        (
              select  to_date(process_dttm) as date 
              ,count(distinct order_number) all_nonappoint_order_cnt
                FROM dw_busdb.tbl_order o
                WHERE o.d = '${pre_day}'
                    AND process_dttm >= '2018-01-01'  --'${pre_day}'
                    AND process_dttm <  '${cur_day}'
                    AND o.order_business_type = 'bus'
                    and order_channel='ctrip' 
                    and utm_source not like "ctripwx%"
                    and utm_source not like "wxscan%" 
                    and utm_source not like "ticketmachine%"
                    and utm_source not like "tmv2%" 
                    and utm_source not like "busweixin%" 
                    and utm_source not like "offzhcz%"
                    and booking_flag in (0,2)
                    and process_state>4 and  user_cancel=0
				group by to_date(process_dttm)
        )c
        on a.date = c.date
)immedi

on a.date = immedi.date




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值