题解 | #统计每个退货率不大于0.5的商品各项指标#

统计2021年10月每个退货率不大于0.5的商品各项指标

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

with t1 as(select product_id,count(product_id) cnt, sum(if_click) click, sum(if_cart) cart, sum(if_payment) payment, sum(if_refund) refund
from tb_user_event
where event_time between '2021-10-01' and '2021-10-31'
group by product_id)
select product_id,
ifnull(round(click/cnt,3),0) ctr,
ifnull(round(cart/click,3),0) cart_rate, 
ifnull(round(payment/cart,3),0) payment_rate, 
ifnull(round(refund/payment,3),0) refund_rate
from t1
where round(refund/payment,3)<=0.5
order by product_id
  • 使用聚合函数得到相关的数据
  • 使用ifnull和round控制格式和去除none
全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务