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

该SQL查询旨在统计2021年10月期间,每个商品的点击率(ctr)、加购转化率(car_rate)、支付转化率(payment_rate)和退款率(refund_rate),并筛选出退货率小于等于0.5的商品。在MySQL中使用ifnull函数,而在Oracle中则使用coalesce函数处理可能的NULL值。查询结果按商品ID排序。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

统计2021年10月每个退货率不大于0.5的商品各项指标_牛客题霸_牛客网s

mysql(ifnull):

select product_id,
format(ifnull(sum(if_click)/nullif(count(*),0),0),3) as ctr,
format(ifnull(sum(if_cart)/nullif(sum(if_click),0),0),3) as car_rate,
format(ifnull(sum(if_payment)/nullif(sum(if_cart),0),0),3) as payment_rate,
format(ifnull(sum(if_refund)/nullif(sum(if_payment),0),0),3) as refund_rate
from tb_user_event
where date_format(event_time,"%Y-%m")='2021-10'
group by product_id
having refund_rate<=0.5
order by product_id

mysql和oracle(coalesce):

select product_id,
format(coalesce(sum(if_click)/nullif(count(*),0),0),3) as ctr,
format(coalesce(sum(if_cart)/nullif(sum(if_click),0),0),3) as car_rate,
format(coalesce(sum(if_payment)/nullif(sum(if_cart),0),0),3) as payment_rate,
format(coalesce(sum(if_refund)/nullif(sum(if_payment),0),0),3) as refund_rate
from tb_user_event
where date_format(event_time,"%Y-%m")='2021-10'
group by product_id
having refund_rate<=0.5
order by product_id

这两个代码唯一的区别就是mysql支持ifnull,oracle不支持ifnull,oracle可以用coalesce,这个mysql也支持。

关于ifnull:http://t.csdn.cn/SEF2V 

关于coalesce:http://t.csdn.cn/cTpk6

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值