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

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

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

select 
round(avg(totalprice),1),
round(avg(buyprice-totalprice),1) from(
    
select distinct 
a.uid,
date(a.event_time) as t,
a.order_id,
    avg(a.total_amount)as totalprice,
sum(b.price*b.cnt) as buyprice,
sum(c.in_price*b.cnt) as inprice

from tb_order_overall a ,tb_order_detail b ,tb_product_info c 
where a.order_id=b.order_id 
and b.product_id=c.product_id 
and date(a.event_time)=
(select min(date(event_time)) from tb_order_overall d 
 where a.uid=d.uid)
 and a.order_id=
 (select min(order_id) from tb_order_overall e 
 where a.uid=e.uid and date(a.event_time)=date(e.event_time))
 group by a.uid,t,a.order_id
 )m where t like '2021-10%'

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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