问题
2021年10月每个有展示记录的退货率不大于0.5的商品各项指标
输出
商品点展比=点击数÷展示数;
加购率=加购数÷点击数;
成单率=付款数÷加购数;
退货率=退款数÷付款数
重点
1.指标计算
商品点展比、加购率、成单率、退货率;
2.分母为0情况处理
ifnull或if、case when赋值;
表
”用户对展示的商品行为表tb_user_event“
uid-用户ID
product_id-商品ID,
event_time-行为时间,
if_click-是否点击
if_cart-是否加购物车,
if_payment-是否付款,
if_refund-是否退货退款
实现
step1:
’’’‘数据来源
有展现的商品是出现在用户展示的行为表的商品
‘’’
from tb_user_event
step2:
where date(event_time) like’2021-10%’ --筛选时间
step3:
group by product_id --商品id分组
step4:
select
–if_click/cart/payment/refund取值是0或1
sum(if_click)/count(product_id) ctr,–点展比
ifnull(sum(if_cart)/sum(if_click),0)cart_rate,和加购率
ifnull(sum(if_payment)/sum(if_cart),0)payment_rate,–成单率
ifnull(sum(if_refund)/sum(if_payment),0)refund_rate–退货率
–round函数保留小数位数
step5:
having refund_rate<= 0.5 --退货率分组过滤
step6:
order by product_id --商品id排序