题解 | #10月的新户客单价和获客成本#

10月的新户客单价和获客成本

https://www.nowcoder.com/practice/d15ee0798e884f829ae8bd27e10f0d64

with
    t1 as (
        select
            uid,
            min(event_time) event_time
        from
            tb_order_overall
        group by
            uid
    )
select distinct
    round(
        (sum(avg(total_amount)) over ()) / sum(count(distinct a.uid)) over (),
        1
    ) avg_amount,
    round(
        (
            (sum(sum(price * cnt)) over ()) - (sum(avg(total_amount)) over ())
        ) / (sum(count(distinct a.uid)) over ()),
        1
    ) avg_cost
from
    tb_order_overall a
    join t1 on a.uid = t1.uid
    and a.event_time = t1.event_time
    join tb_order_detail b on a.order_id = b.order_id
where
    date_format (a.event_time, '%Y-%m') = '2021-10'
group by
    a.uid
limit
    1

全部评论

相关推荐

小谷围鸡肉卷阿姨:+1,腾子投完一动不动
点赞 评论 收藏
分享
10-24 11:10
山西大学 Java
若梦难了:哥们,面试挂是很正常的。我大中厂终面挂,加起来快10次了,继续努力吧。
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务