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

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

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

SELECT
	ROUND(SUM(total_amount) / COUNT(t1.uid), 1) avg_amount,
	ROUND(SUM(total_price - total_amount) / COUNT(t1.uid), 1) avg_cost
FROM
	(
		SELECT
			a.*,
			b.total_price,
			row_number() over(partition BY uid order by event_time) rn
		FROM
			tb_order_overall a
		LEFT JOIN
			(
				SELECT
					order_id,
					SUM(price * cnt) total_price
				FROM
					tb_order_detail
				GROUP BY
					order_id
			)
			b
		ON
			a.order_id = b.order_id
	)
	t1
INNER JOIN
	(
		SELECT
			uid,
			MIN(event_time) first_event_tm
		FROM
			tb_order_overall
		GROUP BY
			uid
		HAVING
			SUBSTR(first_event_tm, 1, 7) = '2021-10'
	)
	t2
ON
	t1.uid = t2.uid
	AND t1.event_time = t2.first_event_tm

全部评论

相关推荐

04-28 11:34
西北大学 运营
牛客4396号:不好意思,这个照片猛一看像丁真
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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