题解 | #计算商城中2021年每月的GMV#
某店铺的各商品毛利率及店铺整体毛利率
http://www.nowcoder.com/practice/65de67f666414c0e8f9a34c08d4a8ba6
select '店铺汇总' product_id, concat(round((1 - sum(cntin_price)/sum(cntprice))*100,1),'%') profit_rate from tb_order_detail t_d join tb_product_info t_i on t_d.product_id = t_i.product_id join tb_order_overall t_o on t_d.order_id = t_o.order_id where shop_id = 901 and date(event_time) >= '2021-10-01'
union
select product_id, concat(profit_rate,'%') profit_rate from ( select product_id, ROUND(100 * (1 - SUM(in_pricecnt) / SUM(pricecnt)), 1) profit_rate from ( select t_d.product_id, in_price, price, cnt from tb_order_detail t_d join tb_product_info t_i on t_d.product_id = t_i.product_id join tb_order_overall t_o on t_d.order_id = t_o.order_id where shop_id = 901 and date(event_time) >= '2021-10-01')t1 group by t1.product_id having profit_rate > 24.9 ORDER BY product_id )t2