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

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

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

with t1 as (select uid,
min(date(event_time)) as min_t
from tb_order_overall tl
group by uid
having min_t between '2021-10-01' and '2021-10-31'
)
,
t2 as (
select *
from(
select t1.uid,
order_id,
event_time,
total_amount,
row_number() over(partition by uid order by event_time) as ranks
from t1 
left join tb_order_overall tl 
on t1.uid=tl.uid) a 
where ranks =1
)

select
    round(avg(total_amount),1) as avg_amount,
    round(avg(cost),1) as avg_cost
    from
(
select t2.order_id,
total_amount,
total_p,
total_p-total_amount as cost
from t2
left join(
select t2.order_id,
sum(price) as total_p
from t2 
left join tb_order_detail td
on t2.order_id=td.order_id
group by t2.order_id
) b
on t2.order_id=b.order_id
) c


全部评论

相关推荐

不愿透露姓名的神秘牛友
01-06 15:18
百度 底层软硬件开发 28*16+4 硕士211
贴心的莲雾向光而行:感觉理想更好,百度这家公司没啥未来
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务