题解 | #10月的新户客单价和获客成本#
10月的新户客单价和获客成本
https://www.nowcoder.com/practice/d15ee0798e884f829ae8bd27e10f0d64
select round(avg(b.total_amount), 1) avg_amount, round(avg(t2.sale_value), 1) avg_cost from( select # 找出所有的新用户,和他们对应的首单单号 uid, min(order_id) first_order from tb_order_overall group by uid having date_format(min(date(event_time)), '%Y-%m') = '2021-10' ) t1 join( select # 获得每个订单的优惠金额 c.order_id, sum(c.price * c.cnt) - max(b.total_amount) sale_value from tb_order_overall b join tb_order_detail c on b.order_id = c.order_id group by c.order_id ) t2 on t1.first_order = t2.order_id join tb_order_overall b # 这个join用来获得所有选出来的订单的总金额 on t1.first_order = b.order_id