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

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

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

哎搞半天终于通过了

-- 请计算2021年10月商城里
-- 所有新用户的首***均交易金额(客单价)和平均获客成本(保留一位小数)。
-- 订单的优惠金额 = 订单明细里的{该订单各商品单价×数量之和} - 订单总表里的{订单总金额} 。
-- 选出新用户

select round(avg(订单总金额),1) avg_amount,round(avg(优惠价格),1) avg_cost
from 
(select a.uid,avg(a.total_amount) 订单总金额,sum(b.price*b.cnt)-avg(a.total_amount) 优惠价格
from tb_order_overall a left join
tb_order_detail b on a.order_id =b.order_id 
left join 
(select uid,min(event_time) mindate
from tb_order_overall
group by uid
having date_format(min(event_time),'%Y-%m')='2021-10')c
on a.uid =c.uid and a.event_time=c.mindate
where c.mindate is not null
group by a.uid) newuser_amount

全部评论

相关推荐

白火同学:能。我当初应届沟通了1200,收简历50,面试10左右吧,加油投吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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