今天给业务提了个数,提取5日内APP自营订单按照支付方式分别计算订单数和用户数
在提数前,查看了表的索引字段,发现时间范围限制字段也在其中,所以弃用平时比较常见的char(created_at,'yyyy-MM-dd'),用大于小于某时间节点来代替函数的使用,极大的加快了运算时间
- select
- to_char(created_at,'yyyy-MM-dd') as order_date,
- COUNT(case when pay_type=4 then ID END) as 使用云闪付支付订单数,
- COUNT(distinct case when pay_type=4 then user_id END) as 使用云闪付支付用户数,
- COUNT(case when pay_type=39 then ID END) as 使用applepay支付订单数,
- COUNT(distinct case when pay_type=39 then user_id END) as 使用applepay支付用户数,
- COUNT(distinct user_id) as APP整体自营购物用户数,
- COUNT(ID) as APP整体自营购物用户数
- from
- (
- select ID,user_id,pay_type,CREATED_AT,order_source,order_platform from o2o.c_order_history
- union all
- select ID,user_id,pay_type,CREATED_AT,order_source,order_platform from o2o.c_order
- )
- where order_source in (1,2,3,7,15,18,33,49,54,56,62,64,77,80,82,83,84,107,108,111,119,126,138,139,154,176,197)
- and order_platform in (0,1)
- and CREATED_AT>=to_date('2022-06-16 00:00:00','YYYY-MM-DD HH24:MI:SS')
- and CREATED_AT<=to_date('2022-06-20 23:59:59','YYYY-MM-DD HH24:MI:SS')
- group by to_char(created_at,'yyyy-MM-dd');