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

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

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

with reg
as(
    select
    uid
    ,min(event_time) first_time
    from tb_order_overall
    group by uid
)

select
round(avg(total_amount), 1) as avg_amount
,round(avg(cost), 1) as cost
from(

    select
    reg.uid as uid
    ,avg(total_amount) as total_amount
    ,sum(price * cnt) - avg(total_amount) as cost
    from tb_order_detail a 
    left join tb_order_overall b 
    on a.order_id = b.order_id
    left join reg
    on b.event_time = reg.first_time
    and b.uid = reg.uid
    where left(event_time, 7) = '2021-10' 
    and first_time is not null 
    group by 1
) t

全部评论

相关推荐

投递米哈游等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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