可运行,易理解 —题解 | #10月的新户客单价和获客成本#

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

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

select round(sum(total)/count(distinct uid),1) as avg_amount
,round((sum(act)-sum(total))/count(distinct uid),1) as avg_cost
from(# 条件过滤:2021-10新增用户及该用户2021-10期间订单的首单
    select 
    uid,avg(total_amount) as total,sum(price*cnt) as act
    from (#表关联,求用户首次日期和付款订单过滤
        select uid
        ,date(event_time) as dt 
        ,min(date(event_time)) over(partition by uid) as first_dt
        ,dense_rank() over(partition by uid order by event_time ) as rn  #首单标签
        ,total_amount
        ,price,cnt
        from tb_order_overall t1
        join tb_order_detail t2 on t1.order_id=t2.order_id
        where t1.status=1
    ) t
    where date_format(first_dt,'%Y-%m')='2021-10' 
    and date_format(dt,'%Y-%m')='2021-10'
    and rn =1
    group by uid
) tt

全部评论

相关推荐

我是没经验的毕业生,这啥情况啊会不会是hr在刷kpi
JamesGosli...:字节boss属于是群发了,我都快入职字节了,其他部门还在和我boss打招呼
点赞 评论 收藏
分享
醉蟀:你不干有的是人干
点赞 评论 收藏
分享
uu们,拒offer时hr很生气怎么办我哭死
爱睡觉的冰箱哥:人家回收你的offer,或者oc后没给你发offer的时候可不会愧疚你,所以你拒了也没必要愧疚他。
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务