select "店铺汇总" as product_id,
concat(round( (1 - SUM(in_price*cnt) / SUM(price*cnt))*100,1),"%") as profit_rate
from tb_order_overall o
join tb_product_info i join tb_order_detail d on d.product_id=i.product_id and d.order_id=o.order_id
where shop_id=901 and DATE_FORMAT(event_time,"%Y-%m")>="2021-10"
union
SELECT *
from(
select product_id,concat(round(avg(1-(in_price)/(price))*100,1),"%") as profit_rate
from(
SELECT d.product_id,in_price,price,cnt,quantity
from tb_order_detail d join tb_product_info i using(product_id)
join tb_order_overall o using(order_id)
where i.shop_id=901 and DATE_FORMAT(o.event_time,"%Y-%m")>=2021-10
)b
group by product_id
HAVING 1-sum(in_price*cnt)/sum(price*cnt)>0.249
order by product_id)c