注意点2: having中的or product_id is null过滤, 是因为with rollup中的product_id汇总列是空值, 所以需要增加一个or条件进行判定having (1 - sum(t1.in_price * t1.cnt) / sum(t1.price * t1.cnt)) > 0.249
select ifnull(t1.product_id, '店铺汇总') as product_id,
concat(round((1 - sum(t1.in_price * t1.cnt) / sum(t1.price * t1.cnt)) * 100, 1), '%') profit_rate
from (
select pi.shop_id, pi.product_id, pi.in_price, od.price, od.cnt
from tb_order_overall oo
left join tb_order_detail od on oo.order_id=od.order_id
left join tb_product_info pi on od.product_id=pi.product_id
where oo.event_time >= '2021-10-01'
and pi.shop_id=901
) t1
group by t1.product_id
with rollup
having (1 - sum(t1.in_price * t1.cnt) / sum(t1.price * t1.cnt)) > 0.249 or product_id is null
order by product_id