此题共包含一张表:
表1:tb_user_event
要解决的问题:
问题:请统计2021年10月每个有展示记录的退货率不大于0.5的商品各项指标,
解题思路:
- 每个有展示记录的商品的各项指标,当分母为0时整体结果记为0,结果中各项指标保留3位小数
- 展示记录=product_id出现的次数
- 退货率=退款数÷付款数
- 商品点展比=点击数÷展示数;
- 加购率=加购数÷点击数;
- 成单率=付款数÷加购数;
- 筛选退货率<= 0.5的商品的各项指标,时间为2021年10月
- 并按商品ID升序排序。
SELECT product_id, ctr, cart_rate, payment_rate, refund_rate
from(
select product_id,
ROUND(if(count(product_id)=0, 0, sum(if_click)/ count(product_id)),3) ctr,
ROUND(if(sum(if_click) = 0, 0, sum(if_cart)/ sum(if_click)),3) cart_rate,
ROUND(if(sum(if_cart) = 0, 0, sum(if_payment)/ sum(if_cart)),3) payment_rate,
ROUND(if(sum(if_payment) = 0, 0, sum(if_refund)/ sum(if_payment)),3) refund_rate
from tb_user_event
where DATE_FORMAT(event_time,'%Y%m') = '202110'
GROUP BY product_id
) t1
where refund_rate <= 0.5
ORDER BY product_id