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

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

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

with
    t1 as (
        select
            uid,
            min(event_time) as event_time
        from
            tb_order_detail
            left join tb_order_overall using (order_id)
        group by
            uid
        having
            date_format (min(event_time), '%Y-%m') = '2021-10'
    ),
    t2 as (
        select
            t1.uid,
            total_amount,
            order_id
        from
            t1
            left join tb_order_overall on t1.uid = tb_order_overall.uid
            and t1.event_time = tb_order_overall.event_time
    ),
    t4 as (
        select
            total_amount,
            sum_price,
            order_id
        from
            t2
            left join (
                select
                    order_id,
                    sum(price) as sum_price
                from
                    t2
                    left join tb_order_detail using (order_id)
                group by
                    order_id
            ) as t3 using (order_id)
    )
select
    round(avg(total_amount),1) as avg_amount,
    round(avg((sum_price - total_amount)),1) as avg_cost
from
    t4

shi山代码

全部评论

相关推荐

程序员牛肉:你这其实一点都没包装,标准的流水线产品。 实习现在不一定能解决你的问题,你太浮躁了。你看了多少源码?看了多少技术博客?真的没必要这么浮躁的着急找实习,沉下心来学习
投递实习岗位前的准备
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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