题解 | #统计2021年10月的商品各项指标#

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

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

相关指标计算:

-- 商品点击率=点击数/展示数

-- 加购率=加购数/点击数

-- 成单率=付款数/加购数

-- 退货率=退款数/付款数

-- 商品点击率=点击数/展示数
-- 加购率=加购数/点击数
-- 成单率=付款数/加购数
-- 退货率=退款数/付款数
with t1 as(
select 
    product_id,
    count(if(if_click=1, 1, null)) as click_cnt,
    count(if_click) as display_cnt,
    count(if(if_cart=1, 1, null)) as cart_cnt,
    count(if(if_refund=1, 1, null)) as refund_cnt,
    count(if(if_payment=1, 1, null)) as pay_cnt
from tb_user_event
where  date_format(event_time, '%Y-%m') = '2021-10'
group by product_id
)
select 
    product_id,
    round(if(display_cnt > 0, click_cnt/ display_cnt, 0), 3) as ctr,
    round(if(click_cnt > 0, cart_cnt/click_cnt, 0),3) as cart_rate,
    round(if(cart_cnt > 0,pay_cnt/cart_cnt, 0), 3) as payment_rate,
    round(if(pay_cnt > 0, refund_cnt/pay_cnt, 0), 3) as refund_rate
from t1
group by product_id having refund_rate <= 0.5
order by product_id
SQL大厂面试题 文章被收录于专栏

牛客网sql大厂面试题题解~

全部评论

相关推荐

03-31 16:42
已编辑
郑州西亚斯学院 后端
Java抽象带篮子:你简历少了几个模块看上去就感觉信息很少,简历怎么写可以看看我发的帖子
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

更多
牛客网
牛客企业服务