题解 | #统计每月退货率不大于0.5的商品各项指标#
统计2021年10月每个退货率不大于0.5的商品各项指标
https://www.nowcoder.com/practice/cbf582d28b794722becfc680847327be
牛客刷题体验感太差了,很多次mysql里跑都是正确的,但是在这里提交答案就跑出来错的数字。
select product_id,
round(count(distinct case when if_click='1 'then id else null end )/count(distinct id) ,3)as ctr,
round(count(distinct case when if_cart='1 'then id else null end )/count(distinct case when if_click='1 'then id else null end ),3)as cart_rate,
round(count(distinct case when if_payment='1' then id else null end) /count(distinct case when if_cart='1 'then id else null end ),3)as payment_rate,
round(count(distinct case when if_refund='1' then id else null end) /count(distinct case when if_payment='1' then id else null end),3) as refund_rate
from tb_user_event
group by 1
having refund_rate<0.5
order by 1;